-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not use heuristic fallback for "module-import"
- Loading branch information
Showing
6 changed files
with
83 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import external0 from "external0"; // module | ||
const external1 = require("external1"); // module | ||
const external2 = require("external2"); // node-commonjs | ||
const external3 = import("external3"); // import | ||
|
||
console.log(external0, external1, external2, external3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
it("module-import should correctly get fallback type", function() { | ||
const content = fs.readFileSync(path.resolve(__dirname, "a.js"), "utf-8"); | ||
expect(content).toContain(`import * as __WEBPACK_EXTERNAL_MODULE_external0__ from "external0";`); // module | ||
expect(content).toContain(`import * as __WEBPACK_EXTERNAL_MODULE_external1__ from "external1";`); // module | ||
expect(content).toContain(`module.exports = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("external2");`); // node-commonjs | ||
expect(content).toContain(`module.exports = import("external3");`); // import | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
findBundle: (i, options) => ["main.js"] | ||
}; |
41 changes: 41 additions & 0 deletions
41
test/configCases/externals/module-import/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** @type {import("../../../../types").Configuration} */ | ||
module.exports = { | ||
target: ["web", "es2020"], | ||
node: { | ||
__dirname: false, | ||
__filename: false | ||
}, | ||
output: { | ||
module: true, | ||
filename: "[name].js" | ||
}, | ||
entry: { | ||
a: "./a", | ||
main: "./index" | ||
}, | ||
optimization: { | ||
concatenateModules: true | ||
}, | ||
experiments: { | ||
outputModule: true | ||
}, | ||
externalsType: "module-import", | ||
externals: [ | ||
function ( | ||
{ context, request, contextInfo, getResolve, dependencyType }, | ||
callback | ||
) { | ||
if (request === "external2") { | ||
return callback(null, "node-commonjs external2"); | ||
} | ||
callback(); | ||
}, | ||
{ | ||
external0: "external0", | ||
external1: "external1", | ||
external3: "external3", | ||
fs: "commonjs fs", | ||
path: "commonjs path" | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters