forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.base.js
More file actions
135 lines (119 loc) · 4.65 KB
/
webpack.config.base.js
File metadata and controls
135 lines (119 loc) · 4.65 KB
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
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const LintExportWebpackPlugin = require('./lint-export-webpack-plugin');
const chalk = require('chalk');
const pkg = require('../package.json');
function compareDependencies(pkgName, dependenciesToCompare, rootDependencies = pkg.dependencies) {
Object.keys(dependenciesToCompare).forEach(name => {
if(!rootDependencies[name]){
console.log(chalk.red(`Dependency error [${pkgName}]: The dependency ${name} not in root package.json!\n`));
}
if (rootDependencies[name] !== dependenciesToCompare[name]) {
if (rootDependencies[name].includes('file:src/')){
return;
}
console.log(chalk.red(`Dependency error [${pkgName}]: The dependency ${name} version can not match in root package.json!\n`));
}
});
}
function checkRootDependencies(dependenciesToCompare, rootDependencies = pkg.dependencies) {
const clientDepsList = Object.values(dependenciesToCompare);
const clientNames = Object.keys(dependenciesToCompare);
Object.keys(rootDependencies).forEach(name => {
if (rootDependencies[name].includes('file:src/')){
return;
}
if (!clientDepsList.some(deps => Object.keys(deps).some(item => item === name))) {
console.log(chalk.red(`Dependency error: The dependency ${name} version can not match in (${clientNames.join('|')}) package.json!\n`));
}
});
}
const packageToClients = ['common', 'classic', 'leaflet', 'openlayers', 'mapboxgl', 'maplibregl'];
const clientDepencies = packageToClients.reduce((list, client) => {
// eslint-disable-next-line import/no-dynamic-require
const clientPkg = require(`../src/${client}/package.json`);
list[clientPkg.name] = clientPkg.dependencies;
return list;
}, {});
for (const clientName in clientDepencies) {
compareDependencies(clientName, clientDepencies[clientName]);
}
checkRootDependencies(clientDepencies);
//包版本(ES6或者ES5)
let moduleVersion = process.env.moduleVersion || 'es5';
//打包公共配置
module.exports = {
target: moduleVersion === 'es5' ? ['es5'] : undefined,
moduleVersion: moduleVersion,
mode: 'production',
//页面入口文件配置
entry: moduleVersion === "es5" ? [
`${__dirname}/../node_modules/core-js/actual/symbol/async-iterator.js`, `${__dirname}/../node_modules/core-js/actual/object/assign.js`
] : [],
output: function (libName, productName) {
let fileName = moduleVersion === 'es6' ? `${productName}-${moduleVersion}` : `${productName}`;
return {
path: `${__dirname}/../dist/${libName}/`,
filename: `${fileName}.js`,
chunkFormat :'commonjs'
};
},
//是否启用压缩
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 {}}}()',
'@antv/g6': 'function(){try{return G6}catch(e){return {}}}()',
'@tensorflow/tfjs': 'function(){try{return tf}catch(e){return {}}}()',
'video.js': 'function(){try{return videojs}catch(e){return {}}}()',
'flv.js': 'function(){try{return flvjs}catch(e){return {}}}()',
'videojs-flvjs-es6': 'function(){try{return;}catch(e){return {}}}()',
'./UGCWasmAll': 'function(){try{return Module}catch(e){return {}}}()'
},
module: {
rules: {
img: {
//图片小于80k采用base64编码
test: /\.(png|jpg|jpeg|gif|woff|woff2|svg|eot|ttf)$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 150000
}
}
},
css: {
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
}
}
},
bannerInfo: function (libName) {
return `
${libName}
Copyright© 2000 - 2025 SuperMap Software Co.Ltd
license: ${pkg.license}
version: v${pkg.version}
`;
},
plugins: function (libName, productName) {
return [
new LintExportWebpackPlugin(libName),
new webpack.BannerPlugin(this.bannerInfo(productName)),
new MiniCssExtractPlugin({filename:`./${productName}.css`}),
new ESLintPlugin({ failOnError: true, files: 'src' })
];
}
};