Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove buildTimeImportMetaUrl #8785

Merged
merged 3 commits into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions packages/vite/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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