Skip to content

Commit

Permalink
support arrow function in umd
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Mar 18, 2022
1 parent 86a8bd9 commit 52abfab
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/library/UmdLibraryPlugin.js
Expand Up @@ -310,9 +310,11 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
: " var a = factory();\n") +
" for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" +
" }\n") +
`})(${
runtimeTemplate.outputOptions.globalObject
}, function(${externalsArguments(externals)}) {\nreturn `,
`})(${runtimeTemplate.outputOptions.globalObject}, ${
runtimeTemplate.supportsArrowFunction()
? `(${externalsArguments(externals)}) =>`
: `function(${externalsArguments(externals)})`
} {\nreturn `,
"webpack/universalModuleDefinition"
),
source,
Expand Down
7 changes: 6 additions & 1 deletion test/ConfigTestCases.template.js
Expand Up @@ -619,7 +619,12 @@ const describeCases = config => {
const fn = runInNewContext
? vm.runInNewContext(code, globalContext, p)
: vm.runInThisContext(code, p);
fn.call(m.exports, ...argValues);
fn.call(
testConfig.nonEsmThis
? testConfig.nonEsmThis(module)
: m.exports,
...argValues
);
document.currentScript = oldCurrentScript;
return m.exports;
}
Expand Down
5 changes: 5 additions & 0 deletions test/configCases/umd/issue-15545/index.js
@@ -0,0 +1,5 @@
it("should compile and run", () => {
expect(hello()).toBe("hello");
});

export function hello() { return "hello"; }
19 changes: 19 additions & 0 deletions test/configCases/umd/issue-15545/webpack.config.js
@@ -0,0 +1,19 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "production",
entry: {
main: "./index.js"
},
output: {
filename: "[name].js",
library: "MyLibrary",
libraryTarget: "umd",
chunkLoading: "jsonp",
chunkFormat: "array-push",
globalObject: "this"
},
optimization: {
minimize: false,
runtimeChunk: "single"
}
};

0 comments on commit 52abfab

Please sign in to comment.