diff --git a/src/Chunk.ts b/src/Chunk.ts index d423f1927db..11dd98f1da5 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -382,7 +382,7 @@ export default class Chunk { for (const { node, resolution } of module.dynamicImports) { if (!resolution) continue; if (resolution instanceof Module) { - if (resolution.isIncluded() && resolution.chunk !== this) { + if (!resolution.chunk.isEmpty && resolution.chunk !== this) { const resolutionChunk = resolution.facadeChunk || resolution.chunk; let relPath = normalize(relative(dirname(this.id), resolutionChunk.id)); if (!relPath.startsWith('../')) relPath = './' + relPath; diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_config.js b/test/chunking-form/samples/dynamic-import-only-reexports/_config.js new file mode 100644 index 00000000000..1848e95f2e8 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_config.js @@ -0,0 +1,6 @@ +module.exports = { + description: 'handles dynamic imports when the imported module only reexports from other modules', + options: { + input: ['main'] + } +}; diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/generated-chunk.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/generated-chunk.js new file mode 100644 index 00000000000..bf7989e606f --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/generated-chunk.js @@ -0,0 +1,7 @@ +define(['exports'], function (exports) { 'use strict'; + + const value = 42; + + exports.value = value; + +}); diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js new file mode 100644 index 00000000000..fdc21863cbe --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js @@ -0,0 +1,5 @@ +define(['require'], function (require) { 'use strict'; + + new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }).then(({ value }) => console.log(value)); + +}); diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/generated-chunk.js new file mode 100644 index 00000000000..9549eb32880 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/generated-chunk.js @@ -0,0 +1,5 @@ +'use strict'; + +const value = 42; + +exports.value = value; diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/main.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/main.js new file mode 100644 index 00000000000..53775291ad7 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/main.js @@ -0,0 +1,3 @@ +'use strict'; + +Promise.resolve(require('./generated-chunk.js')).then(({ value }) => console.log(value)); diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/generated-chunk.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/generated-chunk.js new file mode 100644 index 00000000000..d897952f7d1 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/generated-chunk.js @@ -0,0 +1,3 @@ +const value = 42; + +export { value }; diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/main.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/main.js new file mode 100644 index 00000000000..97a57b60b65 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/main.js @@ -0,0 +1 @@ +import('./generated-chunk.js').then(({ value }) => console.log(value)); diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/generated-chunk.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/generated-chunk.js new file mode 100644 index 00000000000..7dc00320bec --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/generated-chunk.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const value = exports('value', 42); + + } + }; +}); diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/main.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/main.js new file mode 100644 index 00000000000..67f17ffe8c5 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/main.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + module.import('./generated-chunk.js').then(({ value }) => console.log(value)); + + } + }; +}); diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/dep.js b/test/chunking-form/samples/dynamic-import-only-reexports/dep.js new file mode 100644 index 00000000000..46d3ca8c61f --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/dep.js @@ -0,0 +1 @@ +export const value = 42; diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/dynamic.js b/test/chunking-form/samples/dynamic-import-only-reexports/dynamic.js new file mode 100644 index 00000000000..c97bbb820ab --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/dynamic.js @@ -0,0 +1 @@ +export {value} from './dep'; diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/main.js b/test/chunking-form/samples/dynamic-import-only-reexports/main.js new file mode 100644 index 00000000000..984a5a8ab40 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-only-reexports/main.js @@ -0,0 +1 @@ +import('./dynamic').then(({ value }) => console.log(value));