Skip to content

Commit 806ee08

Browse files
committed
support arrow function in umd
1 parent 86a8bd9 commit 806ee08

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

lib/library/UmdLibraryPlugin.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
310310
: " var a = factory();\n") +
311311
" for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" +
312312
" }\n") +
313-
`})(${
314-
runtimeTemplate.outputOptions.globalObject
315-
}, function(${externalsArguments(externals)}) {\nreturn `,
313+
`})(${runtimeTemplate.outputOptions.globalObject}, ${
314+
runtimeTemplate.supportsArrowFunction()
315+
? `(${externalsArguments(externals)}) =>`
316+
: `function(${externalsArguments(externals)})`
317+
} {\nreturn `,
316318
"webpack/universalModuleDefinition"
317319
),
318320
source,

test/ConfigTestCases.template.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,12 @@ const describeCases = config => {
619619
const fn = runInNewContext
620620
? vm.runInNewContext(code, globalContext, p)
621621
: vm.runInThisContext(code, p);
622-
fn.call(m.exports, ...argValues);
622+
fn.call(
623+
testConfig.nonEsmThis
624+
? testConfig.nonEsmThis(module)
625+
: m.exports,
626+
...argValues
627+
);
623628
document.currentScript = oldCurrentScript;
624629
return m.exports;
625630
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
it("should compile and run", () => {
2+
expect(hello()).toBe("hello");
3+
});
4+
5+
export function hello() { return "hello"; }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const CONTEXT = {};
2+
module.exports = {
3+
nonEsmThis(module) {
4+
return CONTEXT;
5+
},
6+
findBundle() {
7+
return ["./runtime.js", "./main.js"];
8+
}
9+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** @type {import("../../../../").Configuration} */
2+
module.exports = {
3+
mode: "production",
4+
entry: {
5+
main: "./index.js"
6+
},
7+
output: {
8+
filename: "[name].js",
9+
library: "MyLibrary",
10+
libraryTarget: "umd",
11+
chunkLoading: "jsonp",
12+
chunkFormat: "array-push",
13+
globalObject: "this"
14+
},
15+
optimization: {
16+
minimize: false,
17+
runtimeChunk: "single"
18+
}
19+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy