2016-09-21 00:58:31 +08:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const PATH_ESLINT = path.join(__dirname, '.eslintrc.js');
|
2016-09-21 03:25:42 +08:00
|
|
|
const PATH_SRC = path.join(__dirname, 'src');
|
2016-09-21 00:58:31 +08:00
|
|
|
|
2016-09-21 15:00:38 +08:00
|
|
|
const isProd = process.argv.indexOf('--prod') >= 0;
|
|
|
|
const envPlugins = isProd ? [
|
|
|
|
new webpack.optimize.OccurrenceOrderPlugin(true),
|
|
|
|
new webpack.optimize.DedupePlugin(),
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
compress: { warnings: false, unused: true, dead_code: true },
|
|
|
|
output: { comments: false }
|
|
|
|
}),
|
|
|
|
] : [];
|
|
|
|
const envOptions = isProd ? {} : { devtool: 'inline-source-map' };
|
|
|
|
|
|
|
|
module.exports = Object.assign(envOptions, {
|
2016-09-21 00:58:31 +08:00
|
|
|
context: __dirname,
|
|
|
|
entry: {
|
2016-09-21 03:25:42 +08:00
|
|
|
'shell-game': PATH_SRC
|
2016-09-21 00:58:31 +08:00
|
|
|
},
|
|
|
|
devServer: {
|
|
|
|
inline: true,
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: path.join(__dirname, 'dist'),
|
|
|
|
filename: '[name].bundle.js',
|
|
|
|
},
|
|
|
|
eslint: {
|
|
|
|
configFile: PATH_ESLINT,
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
loaders: [
|
|
|
|
{
|
|
|
|
test: /\.(js|jsx)$/,
|
|
|
|
include: [PATH_SRC],
|
|
|
|
exclude: [],
|
|
|
|
loader: "babel-loader",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
loaders: ['style', 'css', 'sass']
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
|
|
|
loaders: [
|
|
|
|
'style',
|
|
|
|
'css?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]',
|
|
|
|
'sass'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
preLoaders: [ { test: /\.js$/, include: [PATH_SRC], loader: 'eslint-loader' } ]
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: ['', '.js', '.json', '.jsx'],
|
2016-09-21 03:25:42 +08:00
|
|
|
alias: [
|
|
|
|
{ 'shell-game': PATH_SRC }
|
|
|
|
],
|
2016-09-21 00:58:31 +08:00
|
|
|
},
|
|
|
|
plugins: [
|
2016-09-21 15:00:38 +08:00
|
|
|
...envPlugins,
|
2016-09-21 00:58:31 +08:00
|
|
|
function () {
|
|
|
|
this.plugin('done', () =>
|
|
|
|
setTimeout(() => console.log('\nFinished at ' + (new Date).toLocaleTimeString() + '\n'), 10)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
|
|
]
|
2016-09-21 15:00:38 +08:00
|
|
|
});
|