-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
109 lines (96 loc) · 2.81 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const PRODUCTION = process.env.NODE_ENV === 'production';
const DEVTOOOL = PRODUCTION ? 'source-map' : 'eval-source-map';
function getEntries() {
var entries; // eslint-disable-line no-var
if (!PRODUCTION) {
entries = [
'webpack-hot-middleware/client?reload=true',
'babel-polyfill',
path.join(__dirname, 'src/ui/index.js')
];
} else {
entries = {
app: path.join(__dirname, 'src/ui/index.js'),
vendor: [
'babel-polyfill',
'flexboxgrid',
'isomorphic-fetch',
'react',
'react-flexbox-grid',
'react-redux',
'react-tap-event-plugin',
'redux',
'redux-thunk'
]
};
}
return entries;
}
function getOutput() {
const FILENAME_PATTERN = PRODUCTION ? '[name].[hash].min.js' : '[name].js';
return {
path: path.join(__dirname, '/dist/ui/'),
filename: FILENAME_PATTERN,
publicPath: '/'
};
}
function getPlugins() {
const plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
new HtmlWebpackPlugin({
template: 'src/ui/index.tmpl',
inject: 'body',
filename: 'index.html',
minify: PRODUCTION ? {
collapseWhitespace: true,
html5: true,
removeAttributeQuotes: true
} : false
}),
new webpack.optimize.OccurenceOrderPlugin()
];
if (!PRODUCTION) {
plugins.push(new webpack.HotModuleReplacementPlugin());
plugins.push(new webpack.NoErrorsPlugin());
} else {
plugins.push(new webpack.optimize.UglifyJsPlugin({ comments: false, screwIE8: true, compress: { warnings: false } }));
plugins.push(new webpack.optimize.CommonsChunkPlugin({ names: ['vendor'] }));
plugins.push(new webpack.optimize.DedupePlugin());
}
return plugins;
}
function getLoaders() {
const loaders = [
{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-0']
}
},
{
test: /\.css$/,
loader: 'style!css?modules',
include: /flexboxgrid/
}
];
if (!PRODUCTION) {
loaders[0].query.presets.push('react-hmre');
}
return loaders;
}
module.exports = {
devtool: DEVTOOOL,
entry: getEntries(),
output: getOutput(),
plugins: getPlugins(),
module: {
loaders: getLoaders()
}
};