From 7edcc480dbe2c387701acd321dfa56a7d105069a Mon Sep 17 00:00:00 2001 From: mc-zone Date: Sun, 20 Jan 2019 19:39:51 +0800 Subject: [PATCH] fix: add missed __webpack_require__.e runtime while importing exist module with context --- lib/MainTemplate.js | 9 ++++++++- .../dir-initial/initialModule.js | 1 + test/cases/chunks/import-context-exist-chunk/index.js | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/cases/chunks/import-context-exist-chunk/dir-initial/initialModule.js create mode 100644 test/cases/chunks/import-context-exist-chunk/index.js diff --git a/lib/MainTemplate.js b/lib/MainTemplate.js index db42205e7de..3ea918de934 100644 --- a/lib/MainTemplate.js +++ b/lib/MainTemplate.js @@ -250,7 +250,14 @@ module.exports = class MainTemplate extends Tapable { } else if ( chunk.hasModuleInGraph(m => m.blocks.some(b => b.chunkGroup && b.chunkGroup.chunks.length > 0) - ) + ) || + chunk + .getModules() + .some(m => + m.dependencies.some( + dep => dep.type && dep.type.startsWith("import()") + ) + ) ) { // There async blocks in the graph, so we need to add an empty requireEnsure // function anyway. This can happen with multiple entrypoints. diff --git a/test/cases/chunks/import-context-exist-chunk/dir-initial/initialModule.js b/test/cases/chunks/import-context-exist-chunk/dir-initial/initialModule.js new file mode 100644 index 00000000000..341b43e9dfa --- /dev/null +++ b/test/cases/chunks/import-context-exist-chunk/dir-initial/initialModule.js @@ -0,0 +1 @@ +export default "initialModuleDefault"; diff --git a/test/cases/chunks/import-context-exist-chunk/index.js b/test/cases/chunks/import-context-exist-chunk/index.js new file mode 100644 index 00000000000..2b4f135e586 --- /dev/null +++ b/test/cases/chunks/import-context-exist-chunk/index.js @@ -0,0 +1,8 @@ +it("should resolve when import existed chunk (#8626)", function(done) { + require.context("./dir-initial/"); + const fileName = "initialModule"; + import(`./dir-initial/${fileName}`).then(({default:m}) => { + expect(m).toBe("initialModuleDefault"); + done(); + }).catch(done); +});