-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.prd.js
256 lines (243 loc) · 7.65 KB
/
webpack.config.prd.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
var webpack = require("webpack");
var path = require("path");
var fs = require("fs");
var HtmlWebpackPlugin = require("html-webpack-plugin");
var CopyWebpackPlugin = require("copy-webpack-plugin");
// var ExtractTextPlugin = require("extract-text-webpack-plugin");
var ManifestPlugin = require("webpack-manifest-plugin");
//const CompressionWebpackPlugin = require('compression-webpack-plugin')
// ie9 下单个的css文件超过400k 不被解析
// var CSSSplitWebpackPlugin = require('css-split-webpack-plugin').default
//const marauderDebug = require('sinamfe-marauder-debug')
const es3ifyWebpackPlugin = require("es3ify-webpack-plugin-v2");
const LodashModuleReplacementPlugin = require("lodash-webpack-plugin");
// const ParallelUglifyPlugin = require("webpack-parallel-uglify-plugin");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
//const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const CleanWebpackPlugin = require("clean-webpack-plugin");
const merge = require("webpack-merge");
const webpackCompileParams = require("./webpackCompileParams");
var env = process.env.NODE_ENV;
var plugins = [];
var projectRootPath = path.resolve(__dirname, "./");
let useHash = process.env.NODE_ENV == "single" ? false : true;
// var defaultStyle = ["./assets/styles/businessBlue.less"]
// var orangeStyle = ["./assets/styles/orange.less"]
// var yellowStyle = ["./assets/styles/yellow.less"]
// var blueStyle = ["./assets/styles/blue.less"]
var version_ie8 = "./compatible/dist/index.html";
const version_ie8_bol = fs.existsSync(
path.resolve(projectRootPath, version_ie8)
);
//node环境变量,生产环境:production,开发环境:development
plugins.push(
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(env)
// "process.env.MODE_SPLIT": true
})
);
//plugins.push(new webpack.ExtendedAPIPlugin())
plugins.push(new webpack.optimize.ModuleConcatenationPlugin());
plugins.push(
new webpack.DllReferencePlugin({
context: __dirname,
manifest: merge(require("./vendor/vendor.manifest.json"))
})
);
plugins.push(
new CleanWebpackPlugin(["dist"], {
root: __dirname
})
);
// plugins.push(new CSSSplitWebpackPlugin({size: 3000}))
// plugins.push(
// new ParallelUglifyPlugin({
// cacheDir: ".cache/",
// uglifyJS: {
// output: {
// comments: false
// }
// }
// })
// );
/*
plugins.push(new webpack.optimize.CommonsChunkPlugin({
names: ['bundle', 'edf'],
filename: '[name].[hash:8].min.js',
minChunks: Infinity
}))*/
//'bundle', 'edf', 'icon', 'businessBlueTheme'
plugins.push(new ManifestPlugin());
plugins.push(new es3ifyWebpackPlugin());
plugins.push(new webpack.NoEmitOnErrorsPlugin());
plugins.push(
new HtmlWebpackPlugin({
title: "", //标题
// favicon: "./assets/img/favicon.ico", //favicon路径
filename: "index.html", //生成的html存放路径,相对于 path
template: "index.html", //html模板路径
chunks: ['checkLowBrowser', 'edf'],
hash: false,
inject: "body", //允许插件修改哪些内容,包括head与body`
minify: {
//压缩HTML文件
removeComments: true, //移除HTML中的注释
collapseWhitespace: true, //删除空白符与换行符
removeAttributeQuotes: true
}
})
);
//gzip 压缩
// plugins.push(
// new CompressionWebpackPlugin({
// filename: '[path].gz[query]', // 目标文件名
// cache: true,
// algorithm: 'gzip', // 使用gzip压缩
// test: /\.js(\?.*)?$/i,
// compressionOptions: { level: 1 },
// threshold: 8192, // 资源文件大于时会被压缩
// minRatio: 0.8 // 最小压缩比达到0.8时才会被压缩
// })
// )
//plugins.push(new ExtractTextPlugin('[name].[hash:8].css'))
plugins.push(new LodashModuleReplacementPlugin());
/*
plugins.push(new CopyWebpackPlugin([{
from: './robots.txt',
to: 'robots.txt',
toType: 'file'
}]))
*/
plugins.push(
new CopyWebpackPlugin([])
);
plugins.push(
new CopyWebpackPlugin([{
// from: "./checkLowBrowser.js",
// to: `checkLowBrowser.${useHash ? "[hash:8]." : ""}js`,
// toType:'file'
// // toType: "template"
// },{
from: './vendor',
to: './vendor',
ignore: ['.*']
}])
);
if (version_ie8_bol) {
plugins.push(
new CopyWebpackPlugin([{
from: "./compatible/dist",
to: "./version/ie8",
ignore: [".*"]
}])
);
}
const {
modifyVars,
aliasModule
} = webpackCompileParams();
module.exports = {
devtool: false,
mode: 'production',
entry: {
checkLowBrowser: './checkLowBrowser.js',
edf: [
"edf-app-loader",
"edf-meta-engine",
"edf-component",
"edf-consts",
"edf-utils",
"webapi",
"./index.js"
]
},
optimization: {
splitChunks: { // webpack 4
chunks: 'async',
minSize: 30000,
maxSize: 0,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: '~',
name: true,
cacheGroups: {
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
},
// minimizer: [
// new UglifyJsPlugin({})
// ],
usedExports: true,
},
performance: {
hints: false
},
output: {
path: path.join(__dirname, "/dist/"),
filename: `[name].${useHash ? "[chunkhash:8]." : ""}min.js`,
chunkFilename: `[name].${useHash ? "[chunkhash:8]." : ""}.chunk.js`
},
resolve: {
extensions: [".js"],
alias: Object.assign({
"edf-app-loader": path.resolve(
projectRootPath,
"./app-loader/index.js"
),
"edf-meta-engine": path.resolve(
projectRootPath,
"./meta-engine/index.js"
),
"edf-component": path.resolve(projectRootPath, "./component/index.js"),
"edf-utils": path.resolve(projectRootPath, "./utils/index.js"),
webapi: path.resolve(projectRootPath, "./api/index.js"),
"edf-consts": path.resolve(projectRootPath, "./constant/consts.js"),
"edf-constant": path.resolve(projectRootPath, "./constant/index.js"),
eharts: path.resolve(projectRootPath, "./vendor/echarts.min.js"),
zrender: path.resolve(projectRootPath, "./vendor/zrender.min.js")
},
aliasModule
)
},
externals: {
echarts: "echarts",
zrender: "zrender"
},
module: {
rules: [{
test: /\.js?$/,
exclude: /node_modules/,
use: [{
loader: "babel-loader",
options: {
cacheDirectory: true
}
}]
}, {
test: /\.(eot|woff|woff2|ttf|svg|png|jpe?g|gif|mp4|webm)(\?\S*)?$/,
use: {
loader: "url-loader",
options: {
name: "img/[name].[hash:8].[ext]",
limit: 0,
}
}
}]
},
devServer: {
contentBase: "./dist/",
headers: {
'Access-Control-Allow-Origin': '*'
},
proxy: {
"/v1/*": "http://debug.aierp.cn:8085/",
"/share-oss/*": "http://debug.aierp.cn:8085/"
}
},
plugins: plugins
};