mirror of https://github.com/webpack/webpack.git
fix: return to namespace import when the external request includes a specific export (#20126)
This commit is contained in:
parent
067cc60bdb
commit
27c05c7c39
|
|
@ -443,10 +443,6 @@ const getSourceForModuleExternal = (
|
|||
dependencyMeta,
|
||||
concatenationScope
|
||||
) => {
|
||||
if (!Array.isArray(moduleAndSpecifiers)) {
|
||||
moduleAndSpecifiers = [moduleAndSpecifiers];
|
||||
}
|
||||
|
||||
/** @type {Imported} */
|
||||
let imported = true;
|
||||
if (concatenationScope) {
|
||||
|
|
@ -466,6 +462,15 @@ const getSourceForModuleExternal = (
|
|||
}
|
||||
}
|
||||
|
||||
if (!Array.isArray(moduleAndSpecifiers)) {
|
||||
moduleAndSpecifiers = [moduleAndSpecifiers];
|
||||
}
|
||||
|
||||
// Return to `namespace` when the external request includes a specific export
|
||||
if (moduleAndSpecifiers.length > 1) {
|
||||
imported = true;
|
||||
}
|
||||
|
||||
const initFragment = new ModuleExternalInitFragment(
|
||||
moduleAndSpecifiers[0],
|
||||
imported,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
export const inner = {
|
||||
foo: "foo",
|
||||
bar: "bar"
|
||||
};
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import { foo, bar } from "external";
|
||||
|
||||
it("should have the correct export for array-style external request (e.g. external: ['./external.mjs', 'inner'])", function () {
|
||||
expect(foo).toBe("foo");
|
||||
expect(bar).toBe("bar");
|
||||
});
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const webpack = require("../../../../");
|
||||
|
||||
/** @type {webpack.Configuration} */
|
||||
module.exports = {
|
||||
mode: "production",
|
||||
entry: "./index.js",
|
||||
output: {
|
||||
module: true,
|
||||
library: {
|
||||
type: "module"
|
||||
}
|
||||
},
|
||||
experiments: {
|
||||
outputModule: true
|
||||
},
|
||||
externals: {
|
||||
external: ["./external.mjs", "inner"]
|
||||
},
|
||||
externalsType: "module",
|
||||
plugins: [
|
||||
{
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("Test", (compilation) => {
|
||||
compilation.hooks.processAssets.tap(
|
||||
{
|
||||
name: "copy-webpack-plugin",
|
||||
stage:
|
||||
compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
||||
},
|
||||
() => {
|
||||
const data = fs.readFileSync(
|
||||
path.resolve(__dirname, "./external.mjs")
|
||||
);
|
||||
compilation.emitAsset(
|
||||
"external.mjs",
|
||||
new webpack.sources.RawSource(data)
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
Loading…
Reference in New Issue