Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit bb8f487

Browse files
committed
fix: cache package.json, starter.js and tns-java-classes.js between
compilations
1 parent 847a56f commit bb8f487

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

plugins/GenerateBundleStarterPlugin.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ const { getPackageJson } = require("../projectHelpers");
44
exports.GenerateBundleStarterPlugin = (function() {
55
function GenerateBundleStarterPlugin(bundles) {
66
this.bundles = bundles;
7+
this.files = {};
78
};
89

910
GenerateBundleStarterPlugin.prototype.apply = function(compiler) {
10-
const plugin = this;
11-
plugin.webpackContext = compiler.options.context;
11+
this.webpackContext = compiler.options.context;
1212

13-
compiler.plugin("emit", function (compilation, cb) {
14-
compilation.assets["package.json"] = plugin.generatePackageJson();
15-
compilation.assets["starter.js"] = plugin.generateStarterModule();
16-
plugin.generateTnsJavaClasses(compilation);
13+
compiler.plugin("emit", (compilation, cb) => {
14+
this.addAsset(compilation, "package.json", this.generatePackageJson());
15+
this.addAsset(compilation, "starter.js", this.generateStarterModule());
16+
this.generateTnsJavaClasses(compilation);
1717

1818
cb();
1919
});
@@ -24,23 +24,30 @@ exports.GenerateBundleStarterPlugin = (function() {
2424
const isAndroid = path.indexOf("android") > -1;
2525

2626
if (isAndroid && !compilation.assets["tns-java-classes.js"]) {
27-
compilation.assets["tns-java-classes.js"] = new RawSource("");
27+
this.addAsset(compilation, "tns-java-classes.js", "");
2828
}
2929
}
3030

3131
GenerateBundleStarterPlugin.prototype.generatePackageJson = function () {
3232
const packageJson = getPackageJson(this.webpackContext);
3333
packageJson.main = "starter";
3434

35-
return new RawSource(JSON.stringify(packageJson, null, 4));
35+
return JSON.stringify(packageJson, null, 4);
3636
}
3737

3838
GenerateBundleStarterPlugin.prototype.generateStarterModule = function () {
3939
const moduleSource = this.bundles
4040
.map(bundle => `require("${bundle}")`)
4141
.join("\n");
4242

43-
return new RawSource(moduleSource);
43+
return moduleSource;
44+
}
45+
46+
GenerateBundleStarterPlugin.prototype.addAsset = function(compilation, name, content) {
47+
if (this.files[name] !== content) {
48+
this.files[name] = content;
49+
compilation.assets[name] = new RawSource(content);
50+
}
4451
}
4552

4653
return GenerateBundleStarterPlugin;

0 commit comments

Comments
 (0)