Skip to content

Commit cd32095

Browse files
authoredJun 26, 2022
fix: remove buildTimeImportMetaUrl (#8785)
1 parent 7ae0d3e commit cd32095

File tree

2 files changed

+1
-18
lines changed

2 files changed

+1
-18
lines changed
 

‎packages/vite/rollup.config.ts

-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable no-restricted-globals */
22
import fs from 'node:fs'
33
import path from 'node:path'
4-
import url from 'node:url'
54
import nodeResolve from '@rollup/plugin-node-resolve'
65
import typescript from '@rollup/plugin-typescript'
76
import commonjs from '@rollup/plugin-commonjs'
@@ -140,8 +139,6 @@ function createNodePlugins(
140139
}
141140
}),
142141

143-
buildTimeImportMetaUrl(),
144-
145142
commonjs({
146143
extensions: ['.js'],
147144
// Optional peer deps of ws. Native deps that are mostly for performance.
@@ -286,21 +283,6 @@ function shimDepsPlugin(deps: Record<string, ShimOptions>): Plugin {
286283
}
287284
}
288285

289-
// The use of `import.meta.url` in source code is not reliable after bundling.
290-
// For example, it is affected by the `isEntry` bug brought in by the Rollup CJS plugin
291-
// https://github.com/rollup/plugins/pull/1180
292-
// The better way is to resolve it at build time.
293-
function buildTimeImportMetaUrl(): Plugin {
294-
return {
295-
name: 'buildTimeImportMetaUrl',
296-
resolveImportMeta: (property, chunk) => {
297-
if (property === 'url') {
298-
return `'${url.pathToFileURL(chunk.moduleId).href}'`
299-
}
300-
}
301-
}
302-
}
303-
304286
function licensePlugin() {
305287
return license({
306288
thirdParty(dependencies) {

‎packages/vite/src/node/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const NULL_BYTE_PLACEHOLDER = `__x00__`
6161
export const CLIENT_PUBLIC_PATH = `/@vite/client`
6262
export const ENV_PUBLIC_PATH = `/@vite/env`
6363
export const VITE_PACKAGE_DIR = resolve(
64+
// import.meta.url is `dist/node/constants.js` after bundle
6465
fileURLToPath(import.meta.url),
6566
'../../..'
6667
)

0 commit comments

Comments
 (0)
Please sign in to comment.