-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
103 lines (100 loc) · 2.94 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
const {
createConfig, defineConstants, env, addPlugins,
entryPoint, setOutput, sourceMaps, webpack,
} = require('@webpack-blocks/webpack2')
const babel = require('@webpack-blocks/babel6')
const devServer = require('@webpack-blocks/dev-server2')
const Clean = require('clean-webpack-plugin')
const cssModules = require('./tools/webpack-blocks/css-loader')
const IS_DEV = process.env.NODE_ENV === 'development'
const DIST = `${__dirname}/static/dist`
module.exports = createConfig([
entryPoint({
bundle: [
IS_DEV && 'babel-polyfill',
IS_DEV && 'react-hot-loader/patch',
'./src/main.js',
].filter(f => !!f),
}),
setOutput({
filename: '[name].js',
path: DIST,
publicPath: '/static/dist',
}),
cssModules(),
babel({
babelrc: false, // ignore .babelrc
presets: [
['env', { 'modules': false }],
'stage-0',
'react',
],
plugins: [
IS_DEV && 'react-hot-loader/babel',
'transform-flow-strip-types',
'transform-decorators-legacy',
'transform-class-properties',
!IS_DEV && 'transform-runtime',
// transform-runtime cannot work with react-hot-loader v3
// even with { polyfill: false }
['module-resolver', {
'root': ['./src'],
'alias': { },
}],
].filter(f => !!f),
}),
defineConstants({
'process.env.NODE_ENV': process.env.NODE_ENV,
}),
addPlugins([
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require(`${DIST}/vendor-manifest.json`),
}),
// new webpack.optimize.CommonsChunkPlugin({
// name: 'vendor',
// minChunks: function (module) {
// // this assumes your vendor imports exist in the node_modules directory
// return module.context && (
// module.context.indexOf('node_modules') !== -1 ||
// module.context.indexOf('src/vendor.js') !== -1)
// },
// }),
// //CommonChunksPlugin will now extract all the common modules from vendor and main bundles
// new webpack.optimize.CommonsChunkPlugin({
// name: 'manifest', //But since there are no more common modules between them we end up with just the runtime code included in the manifest file
// }),
]),
env('development', [
devServer({
hot: true,
stats: {
assets: false,
colors: true,
chunks: false,
children: false,
},
}),
devServer.proxy({
'/api': { target: 'http://localhost:3000' },
}),
addPlugins([
// enable HMR globally
new webpack.NamedModulesPlugin(),
// prints more readable module names in the browser console on HMR updates
]),
sourceMaps(),
]),
env('production', [
addPlugins([
new Clean(['dist'], {exclude: ['vendor.dll.js', 'vendor-manifest.json']}),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
output: {
comments: false,
},
}),
]),
sourceMaps(),
]),
])