mirror of https://github.com/webpack/webpack.git
fix: should create export for external
This commit is contained in:
parent
97d4961cd1
commit
84342804dc
|
@ -96,6 +96,7 @@ class ModernModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|||
const definitions =
|
||||
/** @type {BuildMeta} */
|
||||
(module.buildMeta).exportsFinalName;
|
||||
const shortHandedExports = [];
|
||||
const exports = [];
|
||||
|
||||
for (const exportInfo of exportsInfo.orderedExports) {
|
||||
|
@ -107,7 +108,7 @@ class ModernModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|||
|
||||
for (const reexportInfo of exp.orderedExports) {
|
||||
if (
|
||||
!reexportInfo.provided &&
|
||||
reexportInfo.provided === false &&
|
||||
reexportInfo.name === /** @type {string[]} */ (reexport.export)[0]
|
||||
) {
|
||||
shouldContinue = true;
|
||||
|
@ -127,15 +128,26 @@ class ModernModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|||
/** @type {string} */
|
||||
(webpackExportsProperty)
|
||||
];
|
||||
exports.push(
|
||||
|
||||
if (finalName && (finalName.includes(".") || finalName.includes("["))) {
|
||||
exports.push([exportInfo.name, finalName]);
|
||||
} else {
|
||||
shortHandedExports.push(
|
||||
finalName === exportInfo.name
|
||||
? finalName
|
||||
: `${finalName} as ${exportInfo.name}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (exports.length > 0) {
|
||||
result.add(`export { ${exports.join(", ")} };\n`);
|
||||
if (shortHandedExports.length > 0) {
|
||||
result.add(`export { ${shortHandedExports.join(", ")} };\n`);
|
||||
}
|
||||
|
||||
for (const [exportName, final] of exports) {
|
||||
result.add(
|
||||
`export ${compilation.outputOptions.environment.const ? "const" : "var"} ${exportName} = ${final};\n`
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
it('should compile', () => {})
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
findBundle() {
|
||||
return ["main.js"];
|
||||
}
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
export { value } from 'external0'
|
|
@ -0,0 +1,35 @@
|
|||
/** @type {import("../../../../types").Configuration} */
|
||||
module.exports = {
|
||||
mode: "none",
|
||||
entry: { main: "./index.js", test: "./test" },
|
||||
output: {
|
||||
module: true,
|
||||
library: {
|
||||
type: "modern-module"
|
||||
},
|
||||
filename: "[name].js",
|
||||
chunkFormat: "module"
|
||||
},
|
||||
experiments: {
|
||||
outputModule: true
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".js"]
|
||||
},
|
||||
externalsType: "module",
|
||||
externals: ["external0"],
|
||||
optimization: {
|
||||
concatenateModules: true
|
||||
},
|
||||
plugins: [
|
||||
function () {
|
||||
const handler = compilation => {
|
||||
compilation.hooks.afterProcessAssets.tap("testcase", assets => {
|
||||
const source = assets["test.js"].source();
|
||||
expect(source).toContain("export const value");
|
||||
});
|
||||
};
|
||||
this.hooks.compilation.tap("testcase", handler);
|
||||
}
|
||||
]
|
||||
};
|
Loading…
Reference in New Issue