Skip to content

Commit b55dbd5

Browse files
committed
Add scripts to build a Cesium bundle with DllPlugin
1 parent 5a27fed commit b55dbd5

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
# production
1010
/build
11-
/public/cesium/
11+
distdll/
12+
1213

1314
# misc
1415
.DS_Store

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"scripts": {
5656
"start": "node scripts/start.js",
5757
"build": "node scripts/build.js",
58+
"build:dll:cesium": "node ./scripts/buildCesiumDLL.js",
5859
"test": "node scripts/test.js --env=jsdom"
5960
},
6061
"jest": {

scripts/buildCesiumDLL.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const path = require("path");
2+
const webpack = require("webpack");
3+
4+
const compile = require("./webpackCompile");
5+
6+
7+
const cesiumConfig = require('../config/webpack.cesium.dll.config.js');
8+
9+
compile("cesium", cesiumConfig)
10+
.then( ({stats}) => {
11+
});

scripts/webpackCompile.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const webpack = require("webpack");
2+
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
3+
const chalk = require("chalk");
4+
5+
function compile (name, webpackConfig, options = {}) {
6+
if(!webpackConfig.plugins) {
7+
webpackConfig.plugins = [];
8+
}
9+
10+
const {showProgress = true} = options;
11+
const {logStats = true} = options;
12+
13+
if(showProgress) {
14+
webpackConfig.plugins.push(new ProgressBarPlugin({
15+
format: ' build [:bar] ' + chalk.green.bold(':percent') + ' (:elapsed seconds) (:msg)',
16+
clear: false
17+
}));
18+
}
19+
20+
const compiler = webpack(webpackConfig)
21+
22+
23+
return new Promise((resolve, reject) => {
24+
console.log(`Compiling: ${name}`);
25+
26+
compiler.run((err, stats) => {
27+
if (err) return reject(err);
28+
29+
if (stats.hasErrors()) {
30+
return reject(new Error(stats.toString({
31+
errorDetails: true,
32+
warnings: true
33+
})));
34+
}
35+
36+
37+
if(logStats) {
38+
stats.compilation.children = stats.compilation.children.filter(child => {
39+
if(child.name.includes("extract-text")) {
40+
const assetNames = Object.keys(child.assets);
41+
return assetNames.length > 0;
42+
}
43+
44+
return true;
45+
});
46+
const statsString = stats.toString({
47+
chunks: false, // Makes the build much quieter
48+
colors: true,
49+
warnings: true
50+
});
51+
console.log(statsString);
52+
}
53+
54+
resolve({ stats});
55+
});
56+
})
57+
}
58+
59+
60+
61+
62+
63+
module.exports = compile;

0 commit comments

Comments
 (0)