-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathwebpack.config.js
78 lines (66 loc) · 1.85 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
var path = require('path')
var webpack = require('webpack')
var BundleTracker = require('webpack-bundle-tracker')
var ExtractTextPlugin = require('extract-text-webpack-plugin');
function isDevelopmentEnvironment(){
return process.env.NODE_ENV === 'development'
}
function buildEntry(){
entry = {
app: [ './src/index.jsx' ],
}
if (isDevelopmentEnvironment()) {
Object.keys(entry).forEach(function (key) {
entry[key].unshift('webpack/hot/only-dev-server');
entry[key].unshift('webpack-dev-server/client?http://localhost:3000');
});
}
return entry;
}
function buildOutput(){
return {
path: path.resolve(__dirname, 'public/bundles'),
filename: "[name]-[hash].js",
publicPath: isDevelopmentEnvironment() ?
'http://localhost:3000/assets/bundles/' : '/static/bundles/',
};
}
module.exports = {
context: path.resolve(__dirname, 'assets/'),
entry: buildEntry(),
output: buildOutput(),
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new BundleTracker({filename: './webpack-stats.json'}),
new ExtractTextPlugin('[name]-[hash].css'),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
],
module: {
rules: [
{
test: /\.js(x)?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
},
{
test: /\.css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' }
]
}
],
},
resolve: {
modules: ['node_modules'],
extensions: ['.js', '.jsx']
},
mode: process.env.NODE_ENV || 'development'
};