Skip to content

Commit 69f510a

Browse files
author
Chuck Dumont
authored
Merge pull request #27 from chuckdumont/work
Try again to fix build errors when using ExtractTextPlugin
2 parents e776bcb + ee1b974 commit 69f510a

File tree

2 files changed

+18
-37
lines changed

2 files changed

+18
-37
lines changed

lib/DojoAMDMainTemplatePlugin.js

+7-25
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,7 @@ module.exports = class DojoAMDMainTemplatePlugin {
122122
}
123123
}
124124

125-
function hasAMD(chunk) {
126-
var modules = chunk.getModules ? chunk.getModules() : chunk.modules;
127-
return modules.some((module) => {
128-
return module.isAMD;
129-
});
130-
}
131-
132125
compilation.mainTemplate.plugin("bootstrap", function(source, chunk) {
133-
if (!compilation.dojoLoaderDependenciesAdded || !hasAMD(chunk)) {
134-
return source;
135-
}
136126
const buf = [];
137127
const jsonpFunction = this.outputOptions.jsonpFunction || Template.toIdentifier("webpackJsonp" + (this.outputOptions.library || ""));
138128
buf.push(source);
@@ -193,17 +183,11 @@ module.exports = class DojoAMDMainTemplatePlugin {
193183
return this.asString(buf);
194184
});
195185

196-
compilation.mainTemplate.plugin("module-obj", function(source, chunk) {
197-
if (compilation.dojoLoaderDependenciesAdded && hasAMD(chunk)) {
198-
source = source.replace("i: moduleId,", "i: req.absMidsById[moduleId] || moduleId,");
199-
}
200-
return source;
186+
compilation.mainTemplate.plugin("module-obj", function(source) {
187+
return source.replace("i: moduleId,", "i: req.absMidsById[moduleId] || moduleId,");
201188
});
202189

203-
compilation.mainTemplate.plugin("require-extensions", function(source, chunk) {
204-
if (!compilation.dojoLoaderDependenciesAdded || !hasAMD(chunk)) {
205-
return source;
206-
}
190+
compilation.mainTemplate.plugin("require-extensions", function(source) {
207191
const buf = [];
208192
buf.push(source);
209193
buf.push("");
@@ -238,12 +222,10 @@ module.exports = class DojoAMDMainTemplatePlugin {
238222
});
239223

240224
compilation.mainTemplate.plugin("hash", function(hash) {
241-
if (compilation.dojoLoaderDependenciesAdded) {
242-
hash.update("DojoAMDMainTemplate");
243-
hash.update("3"); // Increment this whenever the template code above changes
244-
if (!util.isString(options.loaderConfig)) {
245-
hash.update(JSON.stringify(options.loaderConfig));
246-
}
225+
hash.update("DojoAMDMainTemplate");
226+
hash.update("3"); // Increment this whenever the template code above changes
227+
if (!util.isString(options.loaderConfig)) {
228+
hash.update(JSON.stringify(options.loaderConfig));
247229
}
248230
});
249231
}

lib/DojoLoaderEnsurePlugin.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
*/
1616
const util = require('util');
1717

18-
function hasAMD(chunk) {
19-
var modules = chunk.getModules ? chunk.getModules() : chunk.modules;
20-
return modules.some((module) => {
21-
return module.isAMD;
22-
});
23-
}
24-
2518
function containsModule(chunk, module) {
2619
if (chunk.containsModule) {
2720
return chunk.containsModule(module);
@@ -36,11 +29,8 @@ module.exports = class DojoLoaderEnsurePlugin {
3629
}
3730
apply(compilation) {
3831
// Ensure that the Dojo loader, and optionally the loader config, are included
39-
// in each entry chunk that has any AMD modules.
32+
// in the entry chunks, and only the entry chunks.
4033
compilation.plugin("after-optimize-chunks", (chunks) => {
41-
if (!compilation.dojoLoaderDependenciesAdded) {
42-
return; // Nothing to do for this compilation
43-
}
4434
// Get the loader and loader config
4535
const loaderModule = compilation.modules.find((module) => { return module.rawRequest === this.options.loader;});
4636
if (!loaderModule) {
@@ -54,7 +44,7 @@ module.exports = class DojoLoaderEnsurePlugin {
5444
}
5545
}
5646
chunks.forEach((chunk) => {
57-
if (chunk.hasRuntime() && hasAMD(chunk)) {
47+
if (chunk.hasRuntime()) {
5848
if (!containsModule(chunk, loaderModule)) {
5949
chunk.addModule(loaderModule);
6050
loaderModule.addChunk(chunk);
@@ -63,6 +53,15 @@ module.exports = class DojoLoaderEnsurePlugin {
6353
chunk.addModule(configModule);
6454
configModule.addChunk(chunk);
6555
}
56+
} else {
57+
if (containsModule(chunk, loaderModule)) {
58+
chunk.removeModule(loaderModule);
59+
loaderModule.removeChunk(chunk);
60+
}
61+
if (configModule && containsModule(chunk, configModule)) {
62+
chunk.removeModule(configModule);
63+
configModule.removeChunk(chunk);
64+
}
6665
}
6766
});
6867
});

0 commit comments

Comments
 (0)