-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
264 lines (237 loc) · 8.29 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
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
257
258
259
260
261
262
263
264
var webpack = require("webpack")
var path = require("path")
var fs = require('fs')
const MiniCssExtractPlugin = require('mini-css-extract-plugin') // webpack 4
var HtmlWebpackPlugin = require('html-webpack-plugin')
var CopyWebpackPlugin = require('copy-webpack-plugin')
//var ExtractTextPlugin = require("extract-text-webpack-plugin") // webpack 3
//const marauderDebug = require('sinamfe-marauder-debug')
// const es3ifyWebpackPlugin = require('es3ify-webpack-plugin-v2')
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
const HappyPack = require('happypack')
// ie9 下单个的css文件超过400k 不被解析
//var CSSSplitWebpackPlugin = require('css-split-webpack-plugin').default
//const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const merge = require('webpack-merge')
const webpackCompileParams = require('./webpackCompileParams')
var env = process.env.NODE_ENV
var plugins = []
var projectRootPath = path.resolve(__dirname, './')
const happyThreadPool = HappyPack.ThreadPool({ size: 12 });
var blueStyle = ["./assets/styles/blue.less"]
var tax72Style = ["./assets/styles/tax72.less"]
//node环境变量,生产环境:production,开发环境:development
plugins.push(new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(env),
"process.env.MODE_SPLIT": true
}))
plugins.push(new webpack.optimize.ModuleConcatenationPlugin())
plugins.push(new webpack.ExtendedAPIPlugin())
plugins.push(new webpack.DllReferencePlugin({
context: __dirname,
manifest: merge(require('./vendor/vendor.manifest.json')),
}))
// plugins.push(new es3ifyWebpackPlugin())
plugins.push(new HtmlWebpackPlugin({
title: '' +
'', //标题
// favicon: './assets/img/favicon.ico', //favicon路径
filename: 'index.html', //生成的html存放路径,相对于 path
template: 'index-dev.html', //html模板路径
chunks: ['bundle', 'edf', 'icon', 'tax72Theme'],
hash: false,
inject: 'body'//允许插件修改哪些内容,包括head与body`
}))
//plugins.push(new ExtractTextPlugin('[name].css')) webpack 3
plugins.push(new MiniCssExtractPlugin({ // webpack 4
filename: '[name].css',
chunkFilename: '[id].css',
}))
//plugins.push(new CSSSplitWebpackPlugin({ size: 3000 }))
/*
plugins.push(new OptimizeCssAssetsPlugin(
{
cssProcessorOptions: { discardComments: { removeAll: true } },
canPrint: false
}
))
*/
plugins.push(new CopyWebpackPlugin([{
from: './notfound.html',
to: 'notfound.html',
toType: 'file'
}]))
plugins.push(new CopyWebpackPlugin([{
from: './checkLowBrowser.js',
to: 'checkLowBrowser.js',
toType: 'file'
}]))
plugins.push(new CopyWebpackPlugin([{
from: './vendor',
to: './vendor',
ignore: ['.*']
}]))
plugins.push(new HappyPack({
id: 'babel',
loaders: ['babel-loader?cacheDirectory'],
threadPool: happyThreadPool,
}))
const { modifyVars, aliasModule, start_params } = webpackCompileParams('development')
plugins.push(new HappyPack({
id: 'css',
// loaders: ['css-loader', clientInformation'less-loader'],
loaders: [{
loader: 'css-loader',
}, {
loader: "less-loader",
options: {
"modifyVars": modifyVars,
"javascriptEnabled": true // webpack 4
}
}],
threadPool: happyThreadPool,
}))
//plugins.push(new marauderDebug())
plugins.push(new LodashModuleReplacementPlugin)
/*plugins.push(new webpack.optimize.MinChunkSizePlugin({
minChunkSize: 102400, // ~100kb
}))*/
/*plugins.push(new webpack.optimize.CommonsChunkPlugin({ // webpack 3
names: ['edf'],
filename: '[name].min.js',
minChunks: Infinity
}))*/
function mergeTheme(arr, type) {
const newArr = [...arr]
const modules = ['edf', 'originalStyle']
if (start_params && start_params.toUpperCase() == 'RUNSTART' || !start_params) {
modules.forEach(item => {
newArr.push(`./apps/${item}/theme/${type}.less`)
})
}
else {
modules.forEach(item => {
item = item.toUpperCase()
if (start_params && start_params.includes(item)) {
newArr.push(`./apps/${item}/theme/${type}.less`)
}
})
}
return newArr
}
module.exports = {
// devtool: false,
devtool: 'cheap-module-eval-source-map',
entry: {
bundle: "./index.js",
edf: ["edf-app-loader", "edf-meta-engine", "edf-component", "edf-consts", "edf-utils", "webapi"],
// tax72Theme: tax72Style.concat(mergeTheme([], 'tax72')),
blueTheme: blueStyle.concat(mergeTheme([], 'blue')),
ie: './assets/styles/ie.less'
},
output: {
path: path.join(__dirname, "/dist/"),
filename: '[name].min.js',
chunkFilename: '[name].chunk.js'
},
optimization: { // webpack 4
splitChunks: {
chunks: 'async',
minSize: 30000,
maxSize: 0,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: '~',
name: true,
cacheGroups: {
/*vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10
},*/
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
}
},
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'),
'Theme': '@ttk/component/dist/theme'
}, aliasModule)
},
externals: {
"echarts": 'echarts',
"zrender": 'zrender',
},
module: {
rules: [{
test: /\.(css|less)/,
use: [MiniCssExtractPlugin.loader, { // webpack 4
loader: "css-loader"
}, {
loader: "less-loader",
options: {
modifyVars: modifyVars,
javascriptEnabled: true
}
}]
}, {
test: /\.js?$/,
exclude: /node_modules/,
use: ['happypack/loader?id=babel']
}, {
test: /\.(eot|woff|woff2|ttf|svg|png|jpe?g|gif|mp4|webm)(\?\S*)?$/,
use: {
loader: 'url-loader',
options: {
name: 'img/[name].[ext]',
limit: 0,
// 'imageCDN-webpack?': imageCDN,
// publicPath: __webpack_public_path__,
// runtimePublicPath: () => { window.assetsRoot },
// RuntimePublicPathPlugin: () => { return window.assetsRoot },
}
}
}],
},
devServer: {
contentBase: './dist/',
overlay: {
warnings: true,
errors: true
},
headers: {
'Access-Control-Allow-Origin': '*'
},
proxy: {
// '/v1/*': 'http://debug.aierp.cn:8085/',
'/v1/*': {
// target: 'http://xdz.aierp.cn:8089',
// target:'http://172.16.20.79:8008/',
target: 'http://test.aierp.cn:8089/',
// target:'http://dev.aierp.cn:8089/',
changeOrigin: true,
},
// '/v1/*': {target:'http://dev-xdz.aierp.cn:8089/', changeOrigin: true},
// '/v1/*': 'http://172.16.20.69:8008/',
// '/v1/*': 'http://erpdemo.jchl.com/',
'/share-oss/*': 'http://debug.aierp.cn:8085/',
// '/v1/*':'http://172.16.30.104:8008/',
// '/v1/*': 'http://127.0.0.1:8008/',
}
},
plugins: plugins
}