diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 246fb8f9667a63..c85665f1aadffa 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -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 diff --git a/playground/lib/__tests__/lib.spec.ts b/playground/lib/__tests__/lib.spec.ts index 5940f8ed0a93ce..ce309a2285fe98 100644 --- a/playground/lib/__tests__/lib.spec.ts +++ b/playground/lib/__tests__/lib.spec.ts @@ -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 () => { diff --git a/playground/lib/src/main.js b/playground/lib/src/main.js index ca7adf0a873ae6..59c8e897cb0789 100644 --- a/playground/lib/src/main.js +++ b/playground/lib/src/main.js @@ -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"; }`) }