Skip to content

Commit

Permalink
fix: remove buildTimeImportMetaUrl (#8785)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jun 26, 2022
1 parent 7ae0d3e commit cd32095
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
18 changes: 0 additions & 18 deletions 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'
Expand Down Expand Up @@ -140,8 +139,6 @@ function createNodePlugins(
}
}),

buildTimeImportMetaUrl(),

commonjs({
extensions: ['.js'],
// Optional peer deps of ws. Native deps that are mostly for performance.
Expand Down Expand Up @@ -286,21 +283,6 @@ function shimDepsPlugin(deps: Record<string, ShimOptions>): 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) {
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/constants.ts
Expand Up @@ -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),
'../../..'
)
Expand Down

0 comments on commit cd32095

Please sign in to comment.