diff --git a/lib/library/ModuleLibraryPlugin.js b/lib/library/ModuleLibraryPlugin.js index 36b6cc09b..a6bd4f1cf 100644 --- a/lib/library/ModuleLibraryPlugin.js +++ b/lib/library/ModuleLibraryPlugin.js @@ -124,7 +124,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin { { options, compilation } ) { const result = new ConcatSource(source); - const exportsInfos = options.export + const exportsInfo = options.export ? [ moduleGraph.getExportInfo( module, @@ -151,7 +151,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin { ? "const" : "var"; - for (const exportInfo of exportsInfos) { + for (const exportInfo of exportsInfo) { if (!exportInfo.provided) continue; let shouldContinue = false; @@ -164,6 +164,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin { for (const reexportInfo of exp.orderedExports) { if ( reexportInfo.provided === false && + reexportInfo.name !== "default" && reexportInfo.name === /** @type {string[]} */ (reexport.export)[0] ) { shouldContinue = true; diff --git a/test/configCases/library/module-reexport-external/webpack.config.js b/test/configCases/library/module-reexport-external/webpack.config.js index 2cb33339b..b3f50d549 100644 --- a/test/configCases/library/module-reexport-external/webpack.config.js +++ b/test/configCases/library/module-reexport-external/webpack.config.js @@ -5,7 +5,7 @@ module.exports = { output: { module: true, library: { - type: "modern-module" + type: "module" }, filename: "[name].js", chunkFormat: "module" diff --git a/test/configCases/library/module-reexport-type/file.png b/test/configCases/library/module-reexport-type/file.png new file mode 100644 index 000000000..fb53b9ded Binary files /dev/null and b/test/configCases/library/module-reexport-type/file.png differ diff --git a/test/configCases/library/module-reexport-type/global.d.ts b/test/configCases/library/module-reexport-type/global.d.ts new file mode 100644 index 000000000..a6ec0b37e --- /dev/null +++ b/test/configCases/library/module-reexport-type/global.d.ts @@ -0,0 +1,4 @@ +declare module "*.png" { + const value: string; + export default value; +} diff --git a/test/configCases/library/module-reexport-type/index.ts b/test/configCases/library/module-reexport-type/index.ts index 2b23a65ad..455367e07 100644 --- a/test/configCases/library/module-reexport-type/index.ts +++ b/test/configCases/library/module-reexport-type/index.ts @@ -1,7 +1,15 @@ import { value, T } from './re-export' +import logo from './file.png'; -export { value, T } +type MyType = string; + +export { logo, value, T, MyType } it("should not reexport type", function () { expect(value).toBe(1) }); + +type OtherMyType = string; + +export type { OtherMyType } +export default MyType; diff --git a/test/configCases/library/module-reexport-type/webpack.config.js b/test/configCases/library/module-reexport-type/webpack.config.js index 8be5ca4ad..5a7931540 100644 --- a/test/configCases/library/module-reexport-type/webpack.config.js +++ b/test/configCases/library/module-reexport-type/webpack.config.js @@ -14,7 +14,7 @@ module.exports = { output: { module: true, library: { - type: "modern-module" + type: "module" }, chunkFormat: "module" }, @@ -35,7 +35,24 @@ module.exports = { options: { transpileOnly: true } + }, + { + type: "asset/inline", + test: /\.png$/ } ] - } + }, + plugins: [ + function () { + const handler = compilation => { + compilation.hooks.afterProcessAssets.tap("testcase", assets => { + const source = assets["bundle0.mjs"].source(); + expect(source).toContain( + "export { file_namespaceObject as logo, value };" + ); + }); + }; + this.hooks.compilation.tap("testcase", handler); + } + ] };