Skip to content

Commit

Permalink
fix(esbuild): umd helper insert into wrong position in lib mode (#11988)
Browse files Browse the repository at this point in the history
  • Loading branch information
sun0day authored Feb 17, 2023
1 parent 6eee75c commit 86bc243
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const debug = createDebugger('vite:esbuild')
const INJECT_HELPERS_IIFE_RE =
/^(.*?)((?:const|var)\s+\S+\s*=\s*function\s*\([^)]*\)\s*\{.*?"use strict";)/s
const INJECT_HELPERS_UMD_RE =
/^(.*?)(\(function\([^)]*\)\s*\{.+amd.+function\([^)]*\)\s*\{.*?"use strict";)/s
/^(.*?)(\(function\([^)]*\)\s*\{.+?amd.+?function\([^)]*\)\s*\{.*?"use strict";)/s

let server: ViteDevServer

Expand Down
4 changes: 3 additions & 1 deletion playground/lib/__tests__/lib.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ describe.runIf(isBuild)('build', () => {
const noMinifyCode = readFile('dist/nominify/my-lib-custom-filename.umd.js')
// esbuild helpers are injected inside of the UMD wrapper
expect(code).toMatch(/^\(function\(/)
expect(noMinifyCode).toMatch(/^\(function\(global/)
expect(noMinifyCode).toMatch(
/^\(function\(global.+?"use strict";var.+?function\smyLib\(/s,
)
})

test('iife', async () => {
Expand Down
3 changes: 3 additions & 0 deletions playground/lib/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ export default function myLib(sel) {

// Env vars should not be replaced
console.log(process.env.NODE_ENV)

// make sure umd helper has been moved to the right position
console.log(`amd function(){ "use strict"; }`)
}

0 comments on commit 86bc243

Please sign in to comment.