-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.dev.js
More file actions
185 lines (181 loc) · 6.48 KB
/
webpack.dev.js
File metadata and controls
185 lines (181 loc) · 6.48 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const pathLib = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const CleanPlugin = require('clean-webpack-plugin');
const config = require('./config/config');
const ROOT_PATH = pathLib.resolve(__dirname);
const ENTRY_PATH = pathLib.resolve(ROOT_PATH, 'src');
const ENTRY_PATH_PAGES = pathLib.resolve(ROOT_PATH, 'src/pages');
const OUTPUT_PATH = pathLib.resolve(ROOT_PATH, 'build');
const HappyPack = require('happypack'); //多线程运行
var os = require('os');
var happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
module.exports = {
entry: {
/*index: [
//'react-hot-loader/patch',
//`webpack-hot-middleware/client?path=http://${config.host}:${config.port}/__webpack_hmr`,
//'babel-polyfill',
pathLib.resolve(ENTRY_PATH, 'index.js')
],*/
index: [
'babel-polyfill',
pathLib.resolve(ENTRY_PATH_PAGES, './index/index.js')
],
admin: [
'babel-polyfill',
pathLib.resolve(ENTRY_PATH_PAGES, './admin/index.js')
],
vendor: ['react', 'react-dom', 'react-router-dom', 'react-hot-loader/patch', `webpack-hot-middleware/client?path=http://${config.host}:${config.port}/__webpack_hmr`,]
},
//entry: pathLib.resolve(ENTRY_PATH, 'index.js'),
output: {
path: OUTPUT_PATH,
publicPath: '/',
filename: 'js/[name]-[hash:8].js',
//filename: '[name]-[hash:8].bundle.js',
//chunkFilename: '[name]-[id].[hash:8].bundle.js'
},
devtool: 'cheap-module-eval-source-map',
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader']
//loader: 'happypack/loader?id=babel'
/*,
include: pathLib.resolve(__dirname, 'app/containers/homeAntd')*/
},
{
test: /\.css$/,
exclude: /node_modules/,
use: ['style-loader',
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[name]-[local]-[hash:base64:5]',
importLoaders: 1
}
},
'postcss-loader'
]
},
{
test: /\.css$/,
include: /node_modules/,
use: ['style-loader',
{
loader: 'css-loader'
},
'postcss-loader'
]
},
{
test: /\.less$/,
use: ["style-loader", 'css-loader', "postcss-loader", "less-loader"]
},
{
test: /\.(png|jpg|gif|JPG|GIF|PNG|BMP|bmp|JPEG|jpeg)$/,
exclude: /node_modules/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192
}
}
]
},
{
test: /\.(eot|woff|ttf|woff2|svg)$/,
use: 'url-loader'
}
]
},
plugins: [
new CleanPlugin(['build']),
new ProgressBarPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),//改善chunk传输
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
"progress.env.NODE_ENV": JSON.stringify('development')
}),
//new webpack.optimize.UglifyJsPlugin(), //最小化一切
/*new HtmlWebpackPlugin({
title: "Nitrohe's Blog",
showErrors: true,
}),*/
new HtmlWebpackPlugin({
title: "Nitrohe's Blog",
meta:{
keywords: "",
description: "Nitrohe's Blog"
},
//chunks:[`${item}/${item}`], //引入的js
//template: "./src/template.html",
filename : "index.html" , //html位置
minify:{//压缩html
collapseWhitespace: true,
preserveLineBreaks: true
},
chunks: ['manifest', 'vendor', 'index'],
chunksSortMode:'dependency'
}),
new HtmlWebpackPlugin({
title: "Nitrohe's Admin",
meta:{
keywords: "",
description: "Nitrohe's Admin"
},
//chunks:[`${item}/${item}`], //引入的js
//template: "./src/template.html",
filename : "admin.html" , //html位置
minify:{//压缩html
collapseWhitespace: true,
preserveLineBreaks: true
},
chunks: ['manifest', 'vendor', 'admin'],
chunksSortMode:'dependency'
}),
new webpack.NoEmitOnErrorsPlugin(),//保证出错时页面不阻塞,且会在编译结束后报错
new webpack.HashedModuleIdsPlugin(),//用 HashedModuleIdsPlugin 可以轻松地实现 chunkhash 的稳定化
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
return module.context && module.context.indexOf('node_modules') !== -1;
}
}),
new webpack.optimize.CommonsChunkPlugin({
name: "manifest"
}),
/*,
// modify
new OpenBrowserPlugin({
url: `http://${config.host}:${config.port}`
})*/
new HappyPack({
//多线程运行 默认是电脑核数-1
id: 'babel', //对于loaders id
loaders: ['cache-loader','babel-loader?cacheDirectory'], //是用babel-loader解析
threadPool: happyThreadPool,
verboseWhenProfiling: true, //显示信息
})/*,
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./dll/manifest.json')
})*/
],
resolve: {
alias:{
'@components':pathLib.resolve(__dirname,'./src/components'),
'@reducers':pathLib.resolve(ROOT_PATH, 'src/reducers'),
//'@reducers':'./src/reducers',
'@mlib':pathLib.resolve(__dirname,'./mlib')
},
extensions: ['.js', 'jsx', '.json', '.sass', '.scss', '.less']
}
};