mirror of https://github.com/webpack/webpack.git
Merge pull request #13997 from yujunjung/main
fix: exporting async module as library `type: "module"`
This commit is contained in:
commit
ff69a4a631
|
|
@ -78,6 +78,10 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|||
const result = new ConcatSource(source);
|
||||
const exportsInfo = moduleGraph.getExportsInfo(module);
|
||||
const exports = [];
|
||||
const isAsync = moduleGraph.isAsync(module);
|
||||
if (isAsync) {
|
||||
result.add(`__webpack_exports__ = await __webpack_exports__;\n`);
|
||||
}
|
||||
for (const exportInfo of exportsInfo.orderedExports) {
|
||||
if (!exportInfo.provided) continue;
|
||||
const varName = `__webpack_exports__${Template.toIdentifier(
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
export const a = await Promise.resolve(42);
|
||||
|
|
@ -0,0 +1 @@
|
|||
exports.noTests = true;
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
/** @type {import("../../../../types").Configuration} */
|
||||
module.exports = {
|
||||
entry: "./a.js",
|
||||
output: {
|
||||
filename: "lib.js",
|
||||
library: {
|
||||
type: "module"
|
||||
}
|
||||
},
|
||||
target: "node14",
|
||||
optimization: {
|
||||
minimize: true
|
||||
},
|
||||
experiments: {
|
||||
topLevelAwait: true,
|
||||
outputModule: true
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
it("should get valid export from library", () => {
|
||||
return import("library").then(({ a }) => {
|
||||
expect(a).toBe(42);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
var path = require("path");
|
||||
|
||||
/** @type {function(any, any): import("../../../../types").Configuration} */
|
||||
module.exports = (env, { testPath }) => ({
|
||||
target: "node14",
|
||||
output: {
|
||||
chunkLoading: "import"
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
library: path.resolve(testPath, "../0-create-library/lib.js")
|
||||
}
|
||||
},
|
||||
experiments: {
|
||||
topLevelAwait: true,
|
||||
outputModule: true
|
||||
}
|
||||
});
|
||||
Loading…
Reference in New Issue