diff --git a/packages/vite/rollup.config.ts b/packages/vite/rollup.config.ts index 102a1df2ec4207..8c3e2642d542b9 100644 --- a/packages/vite/rollup.config.ts +++ b/packages/vite/rollup.config.ts @@ -1,7 +1,6 @@ /* eslint-disable no-restricted-globals */ import fs from 'node:fs' import path from 'node:path' -import url from 'node:url' import nodeResolve from '@rollup/plugin-node-resolve' import typescript from '@rollup/plugin-typescript' import commonjs from '@rollup/plugin-commonjs' @@ -140,8 +139,6 @@ function createNodePlugins( } }), - buildTimeImportMetaUrl(), - commonjs({ extensions: ['.js'], // Optional peer deps of ws. Native deps that are mostly for performance. @@ -286,21 +283,6 @@ function shimDepsPlugin(deps: Record): Plugin { } } -// The use of `import.meta.url` in source code is not reliable after bundling. -// For example, it is affected by the `isEntry` bug brought in by the Rollup CJS plugin -// https://github.com/rollup/plugins/pull/1180 -// The better way is to resolve it at build time. -function buildTimeImportMetaUrl(): Plugin { - return { - name: 'buildTimeImportMetaUrl', - resolveImportMeta: (property, chunk) => { - if (property === 'url') { - return `'${url.pathToFileURL(chunk.moduleId).href}'` - } - } - } -} - function licensePlugin() { return license({ thirdParty(dependencies) { diff --git a/packages/vite/src/node/constants.ts b/packages/vite/src/node/constants.ts index d85130aba14499..a7430115b2baab 100644 --- a/packages/vite/src/node/constants.ts +++ b/packages/vite/src/node/constants.ts @@ -61,6 +61,7 @@ export const NULL_BYTE_PLACEHOLDER = `__x00__` export const CLIENT_PUBLIC_PATH = `/@vite/client` export const ENV_PUBLIC_PATH = `/@vite/env` export const VITE_PACKAGE_DIR = resolve( + // import.meta.url is `dist/node/constants.js` after bundle fileURLToPath(import.meta.url), '../../..' )