forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.base.js
84 lines (74 loc) · 2.35 KB
/
webpack.config.base.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
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const pkg = require('../package.json');
//包版本(ES6或者ES5)
let moduleVersion = process.env.moduleVersion || 'es5';
//打包公共配置
module.exports = {
target: moduleVersion === 'es5' ? ['es5'] : undefined,
moduleVersion: moduleVersion,
mode: 'production',
//页面入口文件配置
entry: {},
output: function (libName, productName) {
let fileName = moduleVersion === 'es6' ? `${productName}-${moduleVersion}` : `${productName}`;
return {
path: `${__dirname}/../dist/${libName}/`,
filename: `${fileName}.js`
};
},
//是否启用压缩
optimization: {
minimize: false,
emitOnErrors: false
},
//不显示打包文件大小相关警告
performance: {
hints: false
},
//其它解决方案配置
resolve: {
extensions: ['.js', '.json', '.css']
},
externals: {
echarts: 'function(){try{return echarts}catch(e){return {}}}()',
mapv: 'function(){try{return mapv}catch(e){return {}}}()',
elasticsearch: 'function(){try{return elasticsearch}catch(e){return {}}}()'
},
module: {
rules: {
img: {
//图片小于80k采用base64编码
test: /\.(png|jpg|jpeg|gif|woff|woff2|svg|eot|ttf)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 150000
}
}
]
},
css: {
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
}
}
},
bannerInfo: function (libName) {
return `
${libName}.(${pkg.homepage})
Copyright© 2000 - 2021 SuperMap Software Co.Ltd
license: ${pkg.license}
version: v${pkg.version}
`;
},
plugins: function (libName, productName) {
return [
new webpack.BannerPlugin(this.bannerInfo(productName)),
new MiniCssExtractPlugin({filename:`./${productName}.css`}),
new ESLintPlugin({ failOnError: true, files: 'src' })
];
}
};