-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
148 lines (128 loc) · 3.07 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var dllManifest = require('./dll/vendor-manifest.json');
var VERSION = require('./package').version;
var NODE_ENV = process.env.NODE_ENV || 'development';
var BUILD_NUMBER = process.env.BUILD_NUMBER;
var GIT_COMMIT = process.env.GIT_COMMIT;
var GIT_BRANCH = process.env.GIT_BRANCH;
console.log('NODE_ENV: ', NODE_ENV);
var plugins = [
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(NODE_ENV),
BUILD_NUMBER: JSON.stringify(BUILD_NUMBER),
GIT_COMMIT: JSON.stringify(GIT_COMMIT),
GIT_BRANCH: JSON.stringify(GIT_BRANCH),
VERSION: JSON.stringify(VERSION),
}),
new webpack.ProvidePlugin({
moment: 'moment',
_: 'lodash',
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(__dirname, 'template', 'index.ejs'),
}),
new webpack.DllReferencePlugin({
context: path.join(__dirname, 'src'),
manifest: dllManifest,
}),
];
var output = {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: '[name].[hash].js',
};
var devtool = 'cheap-module-eval-source-map';
switch (NODE_ENV) {
case 'production':
devtool = false;
plugins = plugins.concat([
new webpack.optimize.UglifyJsPlugin({
compress: {
dead_code: true,
drop_console: true,
screw_ie8: true,
},
}),
]);
break;
case 'development':
plugins = plugins.concat([
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin(),
]);
break;
case 'hmr':
case 'test':
output = {
path: path.join(__dirname),
filename: '[name].js',
publicPath: '/',
};
plugins = plugins.concat([
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin(),
]);
break;
default:
throw new Error(`Unsupported env ${NODE_ENV}`);
}
module.exports = {
cache: true,
context: path.join(__dirname, 'src'),
entry: {
main: path.join(__dirname, 'src', 'index.js'),
dll: path.join(__dirname, 'dist', 'dll.vendor.js'),
},
devtool: devtool,
output: output,
plugins: plugins,
devServer: {
port: 3000,
host: '0.0.0.0',
},
module: {
rules: [
{
test: /\.js$/,
enforce: 'pre',
loader: 'eslint-loader',
exclude: /node_modules/,
include: path.join(__dirname, 'src'),
options: {
emitWarning: true,
emitError: true,
},
},
{
test: /\.js$/,
use: 'babel-loader',
include: path.join(__dirname, 'src'),
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.(png|jpg|gif|html|svg|ttf|woff|eot)$/,
loader: 'file-loader',
},
{
test: /\.json$/,
use: 'json-loader',
},
],
},
resolve: {
modules: [
path.join(__dirname, 'src'),
'node_modules',
],
},
};