-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
78 lines (75 loc) · 1.82 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const env = process.env.NODE_ENV || 'development';
const plugins = [
new ExtractTextPlugin('bundle.css'),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(env),
},
}),
new CopyWebpackPlugin([{
from: 'lib/',
to: 'lib/',
}]),
new HtmlWebpackPlugin({
hash: true,
inject: true,
filename: 'index.html',
template: 'index.pug',
}),
];
const publicPath = {
development: '/admin/',
dev: '/admin/',
stable: '/admin/',
online: '/admin/',
};
if (env === 'production') {
plugins.push(new webpack.optimize.UglifyJsPlugin());
}
module.exports = {
entry: './src',
output: {
filename: 'bundle.js',
publicPath: publicPath[env],
path: './build',
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader?presets[]=es2015&presets[]=react&presets[]=stage-0',
}, {
test: /\.less$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader'),
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader'),
}, {
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=images/[name].[ext]',
],
}, {
test: /\.pug$/,
loader: 'pug-loader',
}],
},
externals: {
react: 'var window.React',
'react-dom': 'var window.ReactDOM',
'react-router': 'var window.ReactRouter',
reflux: 'var window.Reflux',
antd: 'var window.antd',
},
devtool: 'cheap-source-map',
plugins,
devServer: {
historyApiFallback: {
index: '/admin/',
},
},
};