fix: fixed work of the non-system type externals for "system" library target

This commit is contained in:
Vladlen Fedosov 2021-07-12 14:23:21 +03:00
parent 444e59f8a4
commit 1f11600acd
4 changed files with 38 additions and 1 deletions

View File

@ -31,7 +31,9 @@ class SystemMainTemplatePlugin {
const { mainTemplate, chunkTemplate } = compilation;
const onRenderWithEntry = (source, chunk, hash) => {
const externals = chunk.getModules().filter(m => m.external);
const externals = chunk
.getModules()
.filter(m => m.external && m.externalType === "system");
// The name this bundle should be registered as with System
const name = this.name

View File

@ -0,0 +1,8 @@
/* This test verifies that webpack externals that have different to System type are properly
* accessible within System.js bundle.
*/
it("should correctly handle externals of different type", function() {
expect(require("rootExt")).toEqual("works");
expect(require("varExt")).toEqual("works");
expect(require("windowExt")).toEqual("works");
});

View File

@ -0,0 +1,16 @@
const System = require("../../../helpers/fakeSystem");
module.exports = {
beforeExecute: () => {
System.init();
},
moduleScope(scope) {
scope.window.windowExt = "works";
scope.rootExt = "works";
scope.varExt = "works";
scope.System = System;
},
afterExecute: () => {
System.execute("(anonym)");
}
};

View File

@ -0,0 +1,11 @@
module.exports = {
output: {
libraryTarget: "system"
},
target: "web",
externals: {
rootExt: "root rootExt",
varExt: "var varExt",
windowExt: "window windowExt"
}
};