diff --git a/lib/DojoLoaderPlugin.js b/lib/DojoLoaderPlugin.js index 220feb6..ee37676 100644 --- a/lib/DojoLoaderPlugin.js +++ b/lib/DojoLoaderPlugin.js @@ -45,7 +45,11 @@ module.exports = class DojoLoaderPlugin { compilation:{value: compilation}, params:{value: params} }); - compiler.plugin("make", this.make.bind(context)); + if (compilation.compiler === compiler) { + // Don't do this for child compilations + // https://github.com/OpenNTF/dojo-webpack-plugin/issues/115 + compiler.plugin("make", this.validateEmbeddedLoader.bind(context)); + } plugin(compilation, [ ["succeed-module", this.succeedModule], ["after-optimize-chunks", this.afterOptimizeChunks] @@ -163,14 +167,14 @@ module.exports = class DojoLoaderPlugin { return loaderScope; } - validateEmbeddedLoader(params, embeddedLoader, filename, callback) { + validateEmbeddedLoader(compilation__, callback) { // Vefiry that embedded loader version and dojo version are the same - params.normalModuleFactory.create({ + this.params.normalModuleFactory.create({ dependencies: [{request: "dojo/package.json"}] }, (err, pkgModule) => { if (!err) { const dojoVersion = require(pkgModule.request).version; - const scope = this.createEmbeddedLoaderScope({}, embeddedLoader, filename); + const scope = this.createEmbeddedLoaderScope({}, this.embeddedLoader, this.filename); if (dojoVersion !== scope.loaderVersion) { err = new Error( `Dojo loader version does not match the version of Dojo. @@ -242,13 +246,6 @@ Refer to https://github.com/OpenNTF/dojo-webpack-plugin/blob/master/README.md#bu this.embeddedLoaderFilename = filename; } - make(compilation__, callback) { - // Make sure the embedded loader was created using the same version of dojo specified in the config - this.validateEmbeddedLoader(this.params, this.embeddedLoader, this.embeddedLoaderFilename, (err) => { - callback(err); - }); - } - succeedModule(module) { const {options} = this; if (!module.issuer) { diff --git a/test/DojoLoaderPlugin.test.js b/test/DojoLoaderPlugin.test.js index 0d8f986..9b6385f 100644 --- a/test/DojoLoaderPlugin.test.js +++ b/test/DojoLoaderPlugin.test.js @@ -66,13 +66,15 @@ describe("DojoLoaderPlugin tests", function() { describe("validateEmbeddedLoader edge cases", function() { it("Should invoke callback with error if nomralModuleFactory.create returns an error", function(done) { var error = new Error("Failed to create module"); - plugin.validateEmbeddedLoader({ + plugin.params = { normalModuleFactory: { create: function(params__, callback) { callback(error); } } - }, "", "", err => { + }; + plugin.embeddedLoader = plugin.filename = ""; + plugin.validateEmbeddedLoader(null, err => { err.should.be.eql(error); done(); });