Skip to content

Commit 09eb4ea

Browse files
【update】兼容ie11 修改打包引入 review by luox
1 parent 1fb45ec commit 09eb4ea

8 files changed

+85
-71
lines changed

build/polyfill.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import TextEncodingPolyfill from '@sinonjs/text-encoding';
2+
3+
if (typeof window['TextEncoder'] !== 'function') {
4+
window['TextEncoder'] = TextEncodingPolyfill.TextEncoder;
5+
window['TextDecoder'] = TextEncodingPolyfill.TextDecoder;
6+
}

build/webpack.config.base.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ module.exports = {
3333

3434
mode: 'production',
3535
//页面入口文件配置
36-
entry: {},
36+
entry: moduleVersion === "es5" ? [
37+
`${__dirname}/../node_modules/core-js/actual/symbol/async-iterator.js`, `${__dirname}/../node_modules/core-js/actual/object/assign.js`, `${__dirname}/polyfill.js`
38+
] : [],
3739

3840
output: function (libName, productName) {
3941
let fileName = moduleVersion === 'es6' ? `${productName}-${moduleVersion}` : `${productName}`;
@@ -109,7 +111,7 @@ module.exports = {
109111
new LintExportWebpackPlugin(libName),
110112
new webpack.BannerPlugin(this.bannerInfo(productName)),
111113
new MiniCssExtractPlugin({filename:`./${productName}.css`}),
112-
new ESLintPlugin({ failOnError: true, files: 'src' }),
114+
new ESLintPlugin({ failOnError: true, files: 'src' })
113115
];
114116
}
115117
};

build/webpack.config.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
target: configBase.target,
1010
mode: configBase.mode,
1111
//页面入口文件配置
12-
entry: configBase.entry,
12+
entry: [`${__dirname}/../src/classic/namespace.js`, ...configBase.entry],
1313
//入口文件输出配置
1414
output: configBase.output(libName, productName),
1515
//是否启用压缩

build/webpack.config.leaflet.js

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,61 @@
11
let configBase = require("./webpack.config.base");
2-
32
//端名
43
const libName = "leaflet";
54
//产品包名
65
const productName = "iclient-leaflet";
76

87
module.exports = {
9-
target: configBase.target,
10-
mode: configBase.mode,
11-
//页面入口文件配置
12-
entry: configBase.entry,
13-
//入口文件输出配置
14-
output: configBase.output(libName, productName),
15-
//是否启用压缩
16-
optimization: configBase.optimization,
17-
//不显示打包文件大小相关警告
18-
performance: configBase.performance,
19-
//其它解决方案配置
20-
resolve: configBase.resolve,
8+
target: configBase.target,
9+
mode: configBase.mode,
10+
//页面入口文件配置
11+
entry: [`${__dirname}/../src/leaflet/namespace.js`, `${__dirname}/../src/leaflet/css/index.js`, ...configBase.entry],
12+
//入口文件输出配置
13+
output: configBase.output(libName, productName),
14+
//是否启用压缩
15+
optimization: configBase.optimization,
16+
//不显示打包文件大小相关警告
17+
performance: configBase.performance,
18+
//其它解决方案配置
19+
resolve: configBase.resolve,
2120

22-
externals: Object.assign({}, configBase.externals, {
23-
'leaflet': 'L',
24-
'@turf/turf': "function(){try{return turf}catch(e){return {}}}()",
25-
'deck.gl': '(function(){try{return DeckGL}catch(e){return {}}})()',
26-
'luma.gl': '(function(){try{return luma}catch(e){return {}}})()',
27-
'webgl-debug': '(function(){try{return webgl-debug}catch(e){return {}}})()',
28-
'xlsx': "function(){try{return XLSX}catch(e){return {}}}()"
29-
}),
21+
externals: Object.assign({}, configBase.externals, {
22+
'leaflet': 'L',
23+
'@turf/turf': "function(){try{return turf}catch(e){return {}}}()",
24+
'deck.gl': '(function(){try{return DeckGL}catch(e){return {}}})()',
25+
'luma.gl': '(function(){try{return luma}catch(e){return {}}})()',
26+
'webgl-debug': '(function(){try{return webgl-debug}catch(e){return {}}})()',
27+
'xlsx': "function(){try{return XLSX}catch(e){return {}}}()"
28+
}),
3029

31-
module: {
32-
rules: (function () {
33-
let moduleRules = [];
34-
moduleRules.push(configBase.module.rules.img);
35-
const babelConfig = {
36-
test: [/\.js$/],
37-
exclude: /setImmediate|webgl-debug/,
38-
loader: 'babel-loader',
39-
options: {
40-
presets: ['@babel/preset-env'],
41-
plugins: [
42-
[
43-
'@babel/plugin-transform-runtime',
44-
{
45-
absoluteRuntime: false,
46-
corejs: false,
47-
helpers: false,
48-
regenerator: true,
49-
useESModules: false
50-
}
51-
]
52-
]
30+
module: {
31+
rules: (function () {
32+
let moduleRules = [];
33+
moduleRules.push(configBase.module.rules.img);
34+
const babelConfig = {
35+
test: [/\.js$/],
36+
exclude: /setImmediate|webgl-debug/,
37+
loader: 'babel-loader',
38+
options: {
39+
presets: ['@babel/preset-env'],
40+
plugins: [
41+
[
42+
'@babel/plugin-transform-runtime',
43+
{
44+
absoluteRuntime: false,
45+
corejs: false,
46+
helpers: false,
47+
regenerator: true,
48+
useESModules: false
5349
}
54-
}
55-
configBase.moduleVersion === "es6" && (babelConfig.include = /FGBLayer|flatgeobuf/);
56-
moduleRules.push(babelConfig);
57-
moduleRules.push(configBase.module.rules.css);
58-
return moduleRules
59-
})()
60-
},
61-
plugins: configBase.plugins(libName, productName)
50+
]
51+
]
52+
}
53+
}
54+
configBase.moduleVersion === "es6" && (babelConfig.include = /FGBLayer|flatgeobuf/);
55+
moduleRules.push(babelConfig);
56+
moduleRules.push(configBase.module.rules.css);
57+
return moduleRules
58+
})()
59+
},
60+
plugins: configBase.plugins(libName, productName)
6261
};

build/webpack.config.mapboxgl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
target: configBase.target,
99
mode: configBase.mode,
1010
//页面入口文件配置
11-
entry: configBase.entry,
11+
entry: [`${__dirname}/../src/mapboxgl/namespace.js` ,`${__dirname}/../src/mapboxgl/css/index.js`, ...configBase.entry],
1212
//入口文件输出配置
1313
output: configBase.output(libName, productName),
1414
//是否启用压缩

build/webpack.config.maplibregl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
target: configBase.target,
99
mode: configBase.mode,
1010
//页面入口文件配置
11-
entry: configBase.entry,
11+
entry: [`${__dirname}/../src/maplibregl/namespace.js`, ...configBase.entry],
1212
//入口文件输出配置
1313
output: configBase.output(libName, productName),
1414
//是否启用压缩

build/webpack.config.openlayers.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ var libName = 'openlayers';
44
//产品包名
55
var productName = 'iclient-openlayers';
66

7-
var argv = JSON.parse(process.env['npm_config_argv']);
8-
var origin = argv.original;
7+
let origin;
8+
if (process.env['npm_config_argv']) {
9+
var argv = JSON.parse(process.env['npm_config_argv']);
10+
origin = argv.original;
11+
} else {
12+
origin = process.env['npm_lifecycle_event'];
13+
}
914
if (origin && origin.includes('deploy-ol')) {
1015
libName = 'ol';
1116
productName = 'iclient-ol';
@@ -34,7 +39,7 @@ module.exports = {
3439
target: configBase.target,
3540
mode: configBase.mode,
3641
//页面入口文件配置
37-
entry: configBase.entry,
42+
entry: [`${__dirname}/../src/openlayers/namespace.js`, `${__dirname}/../src/openlayers/css/index.js`, ...configBase.entry],
3843
//入口文件输出配置
3944
output: configBase.output(libName, productName),
4045
//是否启用压缩

package.json

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
"release-mapboxgl": "npm run release-mapboxgl-es5 && npm run release-mapboxgl-es6",
1818
"release-maplibregl": "npm run release-maplibregl-es5 && npm run release-maplibregl-es6",
1919
"release-classic": "npm run release-classic-es5 && npm run release-classic-es6",
20-
"release-leaflet-es5": "cross-env moduleVersion=es5 npm run deploy-leaflet ./src/leaflet/namespace.js ./src/leaflet/css/index.js && uglifyjs ./dist/leaflet/iclient-leaflet.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/leaflet/iclient-leaflet.min.js && cleancss -o ./dist/leaflet/iclient-leaflet.min.css ./dist/leaflet/iclient-leaflet.css",
21-
"release-openlayers-es5": "cross-env moduleVersion=es5 npm run deploy-openlayers ./src/openlayers/namespace.js ./src/openlayers/css/index.js && uglifyjs ./dist/openlayers/iclient-openlayers.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/openlayers/iclient-openlayers.min.js && cleancss -o ./dist/openlayers/iclient-openlayers.min.css ./dist/openlayers/iclient-openlayers.css",
22-
"release-ol-es5": "cross-env moduleVersion=es5 npm run deploy-ol ./src/openlayers/namespace.js ./src/openlayers/css/index.js && uglifyjs ./dist/ol/iclient-ol.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/ol/iclient-ol.min.js && cleancss -o ./dist/ol/iclient-ol.min.css ./dist/ol/iclient-ol.css",
23-
"release-mapboxgl-es5": "cross-env moduleVersion=es5 npm run deploy-mapboxgl ./src/mapboxgl/namespace.js ./src/mapboxgl/css/index.js && uglifyjs ./dist/mapboxgl/iclient-mapboxgl.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/mapboxgl/iclient-mapboxgl.min.js && cleancss -o ./dist/mapboxgl/iclient-mapboxgl.min.css ./dist/mapboxgl/iclient-mapboxgl.css",
24-
"release-classic-es5": "cross-env moduleVersion=es5 npm run deploy-classic ./src/classic/namespace.js && uglifyjs ./dist/classic/iclient-classic.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/classic/iclient-classic.min.js",
25-
"release-leaflet-es6": "cross-env moduleVersion=es6 npm run deploy-leaflet ./src/leaflet/namespace.js ./src/leaflet/css/index.js && node ./node_modules/uglify-es/bin/uglifyjs ./dist/leaflet/iclient-leaflet-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/leaflet/iclient-leaflet-es6.min.js && cleancss -o ./dist/leaflet/iclient-leaflet.min.css ./dist/leaflet/iclient-leaflet.css",
26-
"release-openlayers-es6": "cross-env moduleVersion=es6 npm run deploy-openlayers ./src/openlayers/namespace.js ./src/openlayers/css/index.js && node ./node_modules/uglify-es/bin/uglifyjs ./dist/openlayers/iclient-openlayers-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/openlayers/iclient-openlayers-es6.min.js && cleancss -o ./dist/openlayers/iclient-openlayers.min.css ./dist/openlayers/iclient-openlayers.css",
27-
"release-ol-es6": "cross-env moduleVersion=es6 npm run deploy-ol ./src/openlayers/namespace.js ./src/openlayers/css/index.js && node ./node_modules/uglify-es/bin/uglifyjs ./dist/ol/iclient-ol-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/ol/iclient-ol-es6.min.js && cleancss -o ./dist/ol/iclient-ol.min.css ./dist/ol/iclient-ol.css",
28-
"release-mapboxgl-es6": "cross-env moduleVersion=es6 npm run deploy-mapboxgl ./src/mapboxgl/namespace.js ./src/mapboxgl/css/index.js && node ./node_modules/uglify-es/bin/uglifyjs ./dist/mapboxgl/iclient-mapboxgl-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/mapboxgl/iclient-mapboxgl-es6.min.js && cleancss -o ./dist/mapboxgl/iclient-mapboxgl.min.css ./dist/mapboxgl/iclient-mapboxgl.css",
29-
"release-classic-es6": "cross-env moduleVersion=es6 npm run deploy-classic ./src/classic/namespace.js && node ./node_modules/uglify-es/bin/uglifyjs ./dist/classic/iclient-classic-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/classic/iclient-classic-es6.min.js",
30-
"release-maplibregl-es5": "cross-env moduleVersion=es5 npm run deploy-maplibregl ./src/maplibregl/namespace.js && uglifyjs ./dist/maplibregl/iclient-maplibregl.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/maplibregl/iclient-maplibregl.min.js",
31-
"release-maplibregl-es6": "cross-env moduleVersion=es6 npm run deploy-maplibregl ./src/maplibregl/namespace.js && node ./node_modules/uglify-es/bin/uglifyjs ./dist/maplibregl/iclient-maplibregl-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/maplibregl/iclient-maplibregl-es6.min.js",
20+
"release-leaflet-es5": "cross-env moduleVersion=es5 npm run deploy-leaflet && uglifyjs ./dist/leaflet/iclient-leaflet.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/leaflet/iclient-leaflet.min.js && cleancss -o ./dist/leaflet/iclient-leaflet.min.css ./dist/leaflet/iclient-leaflet.css",
21+
"release-openlayers-es5": "cross-env moduleVersion=es5 npm run deploy-openlayers && uglifyjs ./dist/openlayers/iclient-openlayers.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/openlayers/iclient-openlayers.min.js && cleancss -o ./dist/openlayers/iclient-openlayers.min.css ./dist/openlayers/iclient-openlayers.css",
22+
"release-ol-es5": "cross-env moduleVersion=es5 npm run deploy-ol && uglifyjs ./dist/ol/iclient-ol.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/ol/iclient-ol.min.js && cleancss -o ./dist/ol/iclient-ol.min.css ./dist/ol/iclient-ol.css",
23+
"release-mapboxgl-es5": "cross-env moduleVersion=es5 npm run deploy-mapboxgl && uglifyjs ./dist/mapboxgl/iclient-mapboxgl.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/mapboxgl/iclient-mapboxgl.min.js && cleancss -o ./dist/mapboxgl/iclient-mapboxgl.min.css ./dist/mapboxgl/iclient-mapboxgl.css",
24+
"release-classic-es5": "cross-env moduleVersion=es5 npm run deploy-classic && uglifyjs ./dist/classic/iclient-classic.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/classic/iclient-classic.min.js",
25+
"release-leaflet-es6": "cross-env moduleVersion=es6 npm run deploy-leaflet && node ./node_modules/uglify-es/bin/uglifyjs ./dist/leaflet/iclient-leaflet-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/leaflet/iclient-leaflet-es6.min.js && cleancss -o ./dist/leaflet/iclient-leaflet.min.css ./dist/leaflet/iclient-leaflet.css",
26+
"release-openlayers-es6": "cross-env moduleVersion=es6 npm run deploy-openlayers && node ./node_modules/uglify-es/bin/uglifyjs ./dist/openlayers/iclient-openlayers-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/openlayers/iclient-openlayers-es6.min.js && cleancss -o ./dist/openlayers/iclient-openlayers.min.css ./dist/openlayers/iclient-openlayers.css",
27+
"release-ol-es6": "cross-env moduleVersion=es6 npm run deploy-ol && node ./node_modules/uglify-es/bin/uglifyjs ./dist/ol/iclient-ol-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/ol/iclient-ol-es6.min.js && cleancss -o ./dist/ol/iclient-ol.min.css ./dist/ol/iclient-ol.css",
28+
"release-mapboxgl-es6": "cross-env moduleVersion=es6 npm run deploy-mapboxgl && node ./node_modules/uglify-es/bin/uglifyjs ./dist/mapboxgl/iclient-mapboxgl-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/mapboxgl/iclient-mapboxgl-es6.min.js && cleancss -o ./dist/mapboxgl/iclient-mapboxgl.min.css ./dist/mapboxgl/iclient-mapboxgl.css",
29+
"release-classic-es6": "cross-env moduleVersion=es6 npm run deploy-classic && node ./node_modules/uglify-es/bin/uglifyjs ./dist/classic/iclient-classic-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/classic/iclient-classic-es6.min.js",
30+
"release-maplibregl-es5": "cross-env moduleVersion=es5 npm run deploy-maplibregl && uglifyjs ./dist/maplibregl/iclient-maplibregl.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/maplibregl/iclient-maplibregl.min.js",
31+
"release-maplibregl-es6": "cross-env moduleVersion=es6 npm run deploy-maplibregl && node ./node_modules/uglify-es/bin/uglifyjs ./dist/maplibregl/iclient-maplibregl-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/maplibregl/iclient-maplibregl-es6.min.js",
3232
"deploy": "webpack --color",
3333
"deploy-leaflet": "webpack --config ./build/webpack.config.leaflet.js --color",
3434
"deploy-openlayers": "webpack --config ./build/webpack.config.openlayers.js --color",
@@ -128,10 +128,12 @@
128128
"dependencies": {
129129
"@elastic/elasticsearch": "^5.6.22",
130130
"@mapbox/vector-tile": "1.3.1",
131+
"@sinonjs/text-encoding": "^0.7.2",
131132
"@supermap/iclient-common": "file:src/common",
132133
"@tensorflow/tfjs": "^3.9.0",
133134
"@turf/turf": "6.5.0",
134135
"canvg": "3.0.10",
136+
"core-js": "^3.30.2",
135137
"echarts": "4.9.0",
136138
"fetch-ie8": "1.5.0",
137139
"fetch-jsonp": "1.1.3",

0 commit comments

Comments
 (0)