Created
March 16, 2016 20:09
-
-
Save nkt/86fb0a7cf6b27f2650c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const webpack = require('webpack'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const env = process.env.NODE_ENV || 'development'; // eslint-disable-line | |
const development = env === 'development'; | |
const production = env === 'production'; | |
const config = module.exports = { | |
context: __dirname, | |
entry: { | |
index: [ | |
path.join(__dirname, 'src/index.js'), | |
path.join(__dirname, 'styles/index.less') | |
], | |
vendor: [ | |
'react', | |
'react-dom', | |
'react-router', | |
'whatwg-fetch' | |
] | |
}, | |
output: { | |
filename: '[name].js', | |
path: path.join(__dirname, 'public'), | |
publicPath: '/static/', | |
chunkFilename: '[id].chunk.js' | |
}, | |
resolve: { | |
alias: { | |
actions: path.join(__dirname, 'src/actions'), | |
components: path.join(__dirname, 'src/components'), | |
services: path.join(__dirname, 'src/services'), | |
stores: path.join(__dirname, 'src/stores'), | |
mixins: path.join(__dirname, 'src/mixins'), | |
constants: path.join(__dirname, 'src/constants'), | |
utils: path.join(__dirname, 'src/utils') | |
} | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.js$/, | |
loader: 'babel', | |
include: [ | |
path.join(__dirname, 'src'), | |
path.join(__dirname, 'node_modules/qs/lib') | |
] | |
}, | |
{ | |
test: /\.less$/, | |
loader: ExtractTextPlugin.extract('style', 'css!autoprefixer!less') | |
}, | |
{ | |
test: /\.svg$/, | |
loader: 'url?limit=2048' | |
}, | |
{ | |
test: /\.(eot|svg|ttf|woff|woff2|otf)/, | |
loader: 'file', | |
include: path.join(__dirname, 'node_modules/font-awesome/fonts') | |
} | |
] | |
}, | |
plugins: [ | |
new webpack.NoErrorsPlugin(), | |
new webpack.optimize.OccurenceOrderPlugin(), | |
new webpack.DefinePlugin({ | |
'__DEV__': JSON.stringify(development), | |
'__DEBUG__': JSON.stringify(development), | |
'process.env.NODE_ENV': JSON.stringify(env) | |
}), | |
new HtmlWebpackPlugin({ | |
inject: false, | |
minify: production, | |
filename: 'index.html', | |
template: path.join(__dirname, 'src/index.html') | |
}), | |
new ExtractTextPlugin('index.css', { | |
allChunks: true | |
}), | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: 'vendor', | |
minChunks: Infinity | |
}) | |
] | |
}; | |
if (production) { | |
config.plugins.push( | |
new webpack.optimize.DedupePlugin(), | |
new webpack.optimize.UglifyJsPlugin({ | |
compressor: { | |
screw_ie8: true, | |
warnings: false | |
} | |
}) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment