This repository was archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
126 lines (121 loc) · 3.14 KB
/
webpack.config.js
File metadata and controls
126 lines (121 loc) · 3.14 KB
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
const path = require('path');
const webpack = require('webpack');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const nodeEnv = process.env.NODE_ENV;
const isProd = nodeEnv === 'production';
const devSvrPort = process.env.DEV_SVR_PORT || 9999;
const commonPlugins = [
new CleanWebpackPlugin(['./public/dist']),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: module =>
module.context && module.context.indexOf('node_modules') !== -1,
filename: isProd ? '[name].[chunkhash].js' : '[name].js',
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(nodeEnv),
},
}),
new webpack.NamedModulesPlugin(),
];
const prodPlugins = [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
new webpack.optimize.UglifyJsPlugin({
output: { comments: false },
sourceMap: true,
}),
new HtmlWebPackPlugin({
inject: false,
filename: path.join(__dirname, './server/index.prod.ejs'),
initialState: '<%= initialState %>',
filesPrefix: '<%= filesPrefix %>',
template: path.join(__dirname, './src/index.ejs'),
}),
];
const devPlugins = [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
];
module.exports = {
devtool: isProd ? 'source-map' : 'cheap-module-eval-source-map',
devServer: {
historyApiFallback: true,
hot: true,
contentBase: path.join(__dirname, './public'),
publicPath: '/assets',
host: '0.0.0.0',
port: devSvrPort,
compress: false,
inline: true,
stats: {
assets: true,
children: false,
chunks: false,
hash: false,
modules: false,
timings: true,
version: false,
warnings: true,
colors: {
green: '\u001b[32m',
},
},
},
entry: {
index: [
'babel-polyfill',
...(isProd ? [] : [
'react-hot-loader/patch',
`webpack-dev-server/client?http://127.0.0.1:${devSvrPort}`,
'webpack/hot/only-dev-server',
]),
path.join(__dirname, './src/'),
],
},
module: {
rules: [
{
test: /\.html$/,
exclude: /node_modules/,
use: { loader: 'file-loader', query: { name: '[name].[ext]' } },
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.json$/,
exclude: /node_modules/,
loader: 'json-loader',
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)(\?.+)?$/,
exclude: /node_modules/,
loader: 'url-loader',
},
],
},
output: isProd ? {
filename: '[name].[chunkhash].js',
path: path.join(__dirname, './public/dist'),
publicPath: '/',
sourceMapFilename: '[file].map',
} : {
filename: 'index.js',
path: path.join(__dirname, './public/dist'),
publicPath: `http://127.0.0.1:${devSvrPort}/assets`,
devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]',
},
plugins: commonPlugins.concat(isProd ? prodPlugins : devPlugins),
stats: {
colors: {
green: '\u001b[32m',
},
},
};