-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.dev.js
153 lines (151 loc) · 4.99 KB
/
webpack.dev.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
149
150
151
152
153
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const os = require('os')
const HappyPack = require('happypack');
const happyThreadPool = HappyPack.ThreadPool({size: os.cpus().length});
const AutoDllPlugin = require('autodll-webpack-plugin');
module.exports = {
entry: {
app: [
'./src/app/app.js'
],
// app2: [
// './src/app/app2.js'
// ],
// vendor:['react','react-dom','react-router-dom'],
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js',
chunkFilename: '[name].[hash].js',
publicPath:''
},
resolve: {
extensions: [
".js", ".jsx"
],
alias: {
'@comp': path.resolve(__dirname, './src/components'),
'@pages': path.resolve(__dirname, './src/pages'),
'@modules': path.resolve(__dirname, './src/modules'),
'@DB': path.resolve(__dirname, './src/db'),
}
},
// 使用externals html里需手动引入一下js,特别注意:还需额外引入moment.js,并放在antd之前,否则会报错
// externals:{
// 'react':'React',
// 'react-dom':'ReactDOM',
// 'react-router-dom':'ReactRouterDOM',
// 'antd':'antd',
// },
module: {
rules: [
{
test: /\.js[x]?$/,
use:[
{
loader:'babel-loader'
}
],
exclude: /node_modules/
}, {
test: /\.(css|scss)/,
use:[
'style-loader',
'css-loader',
'postcss-loader',
'sass-loader'
]
}, {
test: /\.less$/,
use:[
'style-loader',
'css-loader',
'postcss-loader',
'less-loader'
]
}, {
test: /\.(png|jpg|gif|svg)$/,
use: [
{
loader:'url-loader',
options: {
limit: 8192,
name: 'img/[name].[hash:7].[ext]'
}
}
],
},
]
},
// webpack 可以监听文件变化,当它们修改后会重新编译。这个页面介绍了如何启用这个功能,以及当 watch 无法正常运行的时候你可以做的一些调整。
watch: true,
watchOptions:{
ignored: /node_modules/,
},
// 不会生成.map文件,直接放到了js里。测试环境使用
/** Bug Display:
1. File name displayed correctly
2. Line number displayed correctly (CreateLogForm.js?b337:37 I don't know what does the b337 portion stands for though)
3. The file referenced by the error: The original source code is displayed
http://cheng.logdown.com/posts/2016/03/25/679045
**/
devtool: 'cheap-module-eval-source-map',
plugins: [
// new webpack.optimize.CommonsChunkPlugin({
// name:'vendor', //将公共模块打包
// // filename:'vendor.js'
// }),
new HappyPack({id: 'jsx', threadPool: happyThreadPool, loaders: ['babel-loader']}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"'
},
__LOCAL__: false,
__PRO__: true
}),
new HtmlWebpackPlugin({ //生成模板文件
template: './index.html',
filename: 'index.html',
chunks: ['app','vendor'],
// manifest:'static/common-1.0.0.js',
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false,
drop_console: true
},
beautify:false,
comments:false
}),
// new webpack.DllReferencePlugin({
// // context: __dirname,
// manifest: require('./dist/static/common.manifest.json'),
// // name:'dll'
// }),
new AutoDllPlugin({
inject: true, // will inject the DLL bundle to index.html
debug: true,
filename: '[name]-1.0.0.js',
path: './static',
plugins: [
new webpack.optimize.UglifyJsPlugin(),
// 如果不使用本插件,react将会打development环境的包
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"'
},
}),
],
entry: {
common: [
'react',
'react-dom',
'react-router-dom',
]
}
})
]
}