Skip to content

Instantly share code, notes, and snippets.

@linyiru
Last active April 12, 2017 02:28
Show Gist options
  • Save linyiru/3357fd0bc6f06b9305f565e7e09af0d6 to your computer and use it in GitHub Desktop.
Save linyiru/3357fd0bc6f06b9305f565e7e09af0d6 to your computer and use it in GitHub Desktop.
webpack 2.2.x config file
var path = require('path')
var _ = require('lodash')
var webpack = require('webpack')
var assetsPath = path.join(__dirname, '..', 'public', 'assets')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var config = {
context: path.join(__dirname, '..'),
entry: {
application: [
path.join(__dirname, '/javascripts/application.js')
]
},
output: {
path: assetsPath,
filename: '[name]-bundle.js',
publicPath: 'http://localhost:8080/assets/'
},
resolve: {
extensions: ['.js', '.json', '.coffee'],
alias: {
vue: 'vue/dist/vue.js'
}
},
devtool: 'cheap-module-eval-source-map',
devServer: {
hot: true,
// enable HMR on the server
contentBase: assetsPath,
// match the output path
publicPath: 'http://localhost:8080/assets/'
// match the output `publicPath`
},
module: {
rules: [{
test: require.resolve('jquery'),
loader: 'expose?jQuery'
},
{
test: require.resolve('jquery'),
loader: 'expose?$'
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.coffee$/,
loader: 'coffee-loader'
},
{
test: /\.(woff|woff2|eot|ttf|otf)\??.*$/,
loader: 'url-loader?limit=8192&name=[name].[ext]'
},
{
test: /\.(jpe?g|png|gif|svg)\??.*$/,
loader: 'url-loader?limit=8192&name=[name].[ext]'
},
{
test: /\.(sc|c)ss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader?sourceMap',
'sass-loader'
]
})
},
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
new ExtractTextPlugin({
filename: '[name]-bundle.css',
allChunks: true
}),
new webpack.LoaderOptionsPlugin({
debug: true
})
]
}
module.exports = config
@andyyou
Copy link

andyyou commented Apr 11, 2017

resolve: {
    extensions: ['.js', '.json', '.coffee'],
    alias: {
        vue: 'vue/dist/vue.js'
    }
}

@linyiru
Copy link
Author

linyiru commented Apr 12, 2017

@andyyou 感謝大大!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment