forked from relax/relax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
114 lines (110 loc) · 2.78 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var config = require('./config');
var NoErrorsPlugin = webpack.NoErrorsPlugin;
var optimize = webpack.optimize;
var webpackConfig = module.exports = {
entry: {
admin: ['./lib/client/admin.js'],
auth: ['./lib/client/auth.js'],
public: ['./lib/client/public.js']
},
output: {
path: './public/js',
filename: '[name].js',
publicPath: 'http://localhost:' + config.devPort + '/js/'
},
resolve: {
extensions: ['', '.js', '.jsx', '.json']
},
plugins: [
new optimize.OccurenceOrderPlugin(),
new optimize.CommonsChunkPlugin('common.js', ['admin', 'auth', 'public'])
],
module: {
loaders: [
{
test: /\.(js|jsx)$/,
loader: 'babel',
query: {
optional: ['runtime'],
env: {
development: {
plugins: [
'react-transform'
],
extra: {
'react-transform': {
transforms: [{
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module']
}, {
transform: 'react-transform-catch-errors',
imports: ['react', 'redbox-react']
}]
}
}
}
}
},
exclude: /node_modules/
},
{
test: /\.json$/,
loader: 'json'
},
{
test: /\.(woff|woff2|ttf|eot|svg|png|jpg|jpeg|gif)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url'
}
]
},
devServer: {
port: config.devPort,
contentBase: 'http://localhost:' + config.port
}
};
if (process.env.NODE_ENV === 'production') {
webpackConfig.plugins.push(new ExtractTextPlugin('../css/[name].css'));
webpackConfig.module.loaders.push({
test: /\.(less|css)$/,
loader: ExtractTextPlugin.extract(
'style-loader',
'css-loader!less!autoprefixer',
{
publicPath: '../css/'
}
)
});
webpackConfig.plugins.push(
new webpack.optimize.UglifyJsPlugin({
mangle: true,
compress: {
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true,
warnings: false
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new NoErrorsPlugin()
);
webpackConfig.devtool = 'source-map';
} else {
webpackConfig.module.loaders.push({
test: /\.(less|css)$/,
loader: 'style!css!less!autoprefixer'
});
webpackConfig.devtool = 'eval';
}