-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.common.js
73 lines (71 loc) · 2.39 KB
/
webpack.common.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
const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: {
customPrimitive: './src/index.js'
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['dist']
}),
new CopyWebpackPlugin([
// 'Apps/**/*',
'index.html',
{
// from: 'Static/XbsjCesium', // 使用指定的XbsjCesium
from: process.env.XBSJ_IMPORT !== 'external' ? './node_modules/earthsdk/dist/XbsjCesium' : 'Static/XbsjCesium',
to: 'XbsjCesium',
toType: 'dir'
},
{
// from: 'Static/XbsjEarth', // 使用指定的XbsjEarth
from: process.env.XBSJ_IMPORT !== 'external' ? './node_modules/earthsdk/dist/XbsjEarth' : 'Static/XbsjEarth',
to: 'XbsjEarth',
toType: 'dir'
},
{
from: 'Static/assets',
to: 'XbsjEarth-Plugins/customPrimitive/assets',
toType: 'dir'
},
{
from: 'Apps',
to: 'Apps',
toType: 'dir',
transform(content, path) {
if (!path.endsWith('.html')) {
return content;
}
var cs = content.toString('utf8');
if (process.env.NODE_ENV === 'xbsjDebug') {
// cs = cs.replace(/\/\/xbsjDebug\b/g, '');
cs = cs.replace(/\<head>/, `<head>
<script>
window.xbsjEarthDir = 'http://127.0.0.1:9529/XbsjEarth/';
</script>`)
cs = cs.replace(/['"].*\/XbsjEarth.js['"]/, `"http://127.0.0.1:9529/XbsjEarth/XbsjEarth.js"`);
return cs;
} else if (process.env.NODE_ENV === 'xbsjDebug2') {
// cs = cs.replace(/\/\/xbsjDebug2\b/g, '');
cs = cs.replace(/\<head>/, `<head>
<script>
window.xbsjEarthDir = 'http://127.0.0.1:9529/XbsjEarth/';
window.xbsjCesiumDir = 'http://127.0.0.1:9527/XbsjCesium/';
</script>`)
cs = cs.replace(/['"].*\/XbsjEarth.js['"]/, `"http://127.0.0.1:9529/XbsjEarth/XbsjEarth.js"`);
return cs;
} else {
return content;
}
},
}
]),
new webpack.HotModuleReplacementPlugin(),
],
output: {
filename: 'XbsjEarth-Plugins/customPrimitive/[name].js',
path: path.resolve(__dirname, 'dist')
}
};