Skip to content

Commit 86bc243

Browse files
authoredFeb 17, 2023
fix(esbuild): umd helper insert into wrong position in lib mode (#11988)
1 parent 6eee75c commit 86bc243

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed
 

‎packages/vite/src/node/plugins/esbuild.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const debug = createDebugger('vite:esbuild')
2929
const INJECT_HELPERS_IIFE_RE =
3030
/^(.*?)((?:const|var)\s+\S+\s*=\s*function\s*\([^)]*\)\s*\{.*?"use strict";)/s
3131
const INJECT_HELPERS_UMD_RE =
32-
/^(.*?)(\(function\([^)]*\)\s*\{.+amd.+function\([^)]*\)\s*\{.*?"use strict";)/s
32+
/^(.*?)(\(function\([^)]*\)\s*\{.+?amd.+?function\([^)]*\)\s*\{.*?"use strict";)/s
3333

3434
let server: ViteDevServer
3535

‎playground/lib/__tests__/lib.spec.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ describe.runIf(isBuild)('build', () => {
1919
const noMinifyCode = readFile('dist/nominify/my-lib-custom-filename.umd.js')
2020
// esbuild helpers are injected inside of the UMD wrapper
2121
expect(code).toMatch(/^\(function\(/)
22-
expect(noMinifyCode).toMatch(/^\(function\(global/)
22+
expect(noMinifyCode).toMatch(
23+
/^\(function\(global.+?"use strict";var.+?function\smyLib\(/s,
24+
)
2325
})
2426

2527
test('iife', async () => {

‎playground/lib/src/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ export default function myLib(sel) {
66

77
// Env vars should not be replaced
88
console.log(process.env.NODE_ENV)
9+
10+
// make sure umd helper has been moved to the right position
11+
console.log(`amd function(){ "use strict"; }`)
912
}

0 commit comments

Comments
 (0)
Please sign in to comment.