|
1 | 1 | /* eslint-disable node/no-extraneous-import */ |
2 | 2 | import path from 'path' |
3 | 3 | import { createHash } from 'crypto' |
| 4 | +import { createRequire } from 'module' |
| 5 | +import { fileURLToPath } from 'url' |
4 | 6 | import { build } from 'vite' |
5 | 7 | import MagicString from 'magic-string' |
6 | 8 | import type { |
@@ -171,6 +173,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { |
171 | 173 | } |
172 | 174 | } |
173 | 175 |
|
| 176 | + const _require = createRequire(import.meta.url) |
174 | 177 | const legacyPostPlugin: Plugin = { |
175 | 178 | name: 'vite:legacy-post-process', |
176 | 179 | enforce: 'post', |
@@ -331,7 +334,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { |
331 | 334 | useBuiltIns: needPolyfills ? 'usage' : false, |
332 | 335 | corejs: needPolyfills |
333 | 336 | ? { |
334 | | - version: require('core-js/package.json').version, |
| 337 | + version: _require('core-js/package.json').version, |
335 | 338 | proposals: false |
336 | 339 | } |
337 | 340 | : undefined, |
@@ -557,7 +560,7 @@ async function buildPolyfillChunk( |
557 | 560 | minify = minify ? 'terser' : false |
558 | 561 | const res = await build({ |
559 | 562 | // so that everything is resolved from here |
560 | | - root: __dirname, |
| 563 | + root: path.dirname(fileURLToPath(import.meta.url)), |
561 | 564 | configFile: false, |
562 | 565 | logLevel: 'error', |
563 | 566 | plugins: [polyfillsPlugin(imports, externalSystemJS)], |
|
0 commit comments