-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathwebpack.config.js
107 lines (103 loc) · 2.54 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
const webpack = require('webpack')
const path = require('path')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const DIST_PATH = './lib/template/assets/script'
const isProd = process.env.NODE_ENV === 'production'
const showAnalysis = process.env.ANA === 'true'
const watch = process.env.WATCH === 'true'
// 将 css 从文本中提取出来,参数为资源存放的位置
let plugins = [new ExtractTextPlugin('../css/weweb.min.css')]
if (showAnalysis) {
plugins = plugins.concat([new BundleAnalyzerPlugin()])
}
if (isProd) {
plugins = plugins.concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.AggressiveMergingPlugin(), // Merge chunks
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_debugger: true,
dead_code: true,
properties: true,
evaluate: true
},
output: {
comments: false
}
}),
new webpack.optimize.ModuleConcatenationPlugin()
])
}
function getPath (rPath) {
return path.resolve(__dirname, rPath)
}
function getSourcePath (rPath) {
return getPath(`./src/${rPath}`)
}
module.exports = {
entry: {
weweb: getSourcePath('index.js')
},
output: {
filename: '[name].js',
publicPath: 'script/',
chunkFilename: '[name].wd.chunk.js',
path: getPath(DIST_PATH)
},
watch: watch,
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['env', 'stage-0']
}
},
{
test: /\.html/,
loader: 'html-loader'
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: {
loader: 'css-loader',
options: { minimize: true }
}
})
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
// 注意此处 outputPath 为输出结果的地址
'file-loader?name=[name].[ext]&publicPath=&outputPath=../images/'
// 'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
},
{
test: /\.et/,
loader: 'ei-loader'
},
{
test: /\.json$/,
loader: 'json'
}
]
},
stats: {
modulesSort: 'size',
chunksSort: 'size',
assetsSort: 'size'
},
plugins: plugins
}