mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
fix(optimizer): workaround firefox's false warning for no sources source map (#18665)
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
This commit is contained in:
parent
f005461ecc
commit
473424ee8d
@ -673,6 +673,25 @@ export function runOptimizeDeps(
|
|||||||
browserHash: metadata.browserHash,
|
browserHash: metadata.browserHash,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// workaround Firefox warning by removing blank source map reference
|
||||||
|
// https://github.com/evanw/esbuild/issues/3945
|
||||||
|
const output = meta.outputs[o]
|
||||||
|
// filter by exact bytes of an empty source map
|
||||||
|
if (output.bytes === 93) {
|
||||||
|
const jsMapPath = path.resolve(o)
|
||||||
|
const jsPath = jsMapPath.slice(0, -4)
|
||||||
|
if (fs.existsSync(jsPath) && fs.existsSync(jsMapPath)) {
|
||||||
|
const map = JSON.parse(fs.readFileSync(jsMapPath, 'utf-8'))
|
||||||
|
if (map.sources.length === 0) {
|
||||||
|
const js = fs.readFileSync(jsPath, 'utf-8')
|
||||||
|
fs.writeFileSync(
|
||||||
|
jsPath,
|
||||||
|
js.slice(0, js.lastIndexOf('//# sourceMappingURL=')),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
export const all = 'all'
|
||||||
|
export { sub } from './sub.js'
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "@vitejs/test-dep-source-map-no-sources",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"exports": {
|
||||||
|
"./*": "./*"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
export const sub = 'sub'
|
@ -299,3 +299,9 @@
|
|||||||
text('.dep-with-asset-ext-prebundled', isPreBundled)
|
text('.dep-with-asset-ext-prebundled', isPreBundled)
|
||||||
text('.dep-with-asset-ext-no-dual-package', original === reexport)
|
text('.dep-with-asset-ext-no-dual-package', original === reexport)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
// manually check Firefox doesn't show warning in devtool debugger
|
||||||
|
import * as sub from '@vitejs/test-dep-source-map-no-sources/sub.js'
|
||||||
|
import * as all from '@vitejs/test-dep-source-map-no-sources/all.js'
|
||||||
|
</script>
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
"@vitejs/test-dep-optimize-exports-with-root-glob": "file:./dep-optimize-exports-with-root-glob",
|
"@vitejs/test-dep-optimize-exports-with-root-glob": "file:./dep-optimize-exports-with-root-glob",
|
||||||
"@vitejs/test-dep-optimize-with-glob": "file:./dep-optimize-with-glob",
|
"@vitejs/test-dep-optimize-with-glob": "file:./dep-optimize-with-glob",
|
||||||
"@vitejs/test-dep-relative-to-main": "file:./dep-relative-to-main",
|
"@vitejs/test-dep-relative-to-main": "file:./dep-relative-to-main",
|
||||||
|
"@vitejs/test-dep-source-map-no-sources": "file:./dep-source-map-no-sources",
|
||||||
"@vitejs/test-dep-with-asset-ext1.pdf": "file:./dep-with-asset-ext/dep1",
|
"@vitejs/test-dep-with-asset-ext1.pdf": "file:./dep-with-asset-ext/dep1",
|
||||||
"@vitejs/test-dep-with-asset-ext2.pdf": "file:./dep-with-asset-ext/dep2",
|
"@vitejs/test-dep-with-asset-ext2.pdf": "file:./dep-with-asset-ext/dep2",
|
||||||
"@vitejs/test-dep-with-builtin-module-cjs": "file:./dep-with-builtin-module-cjs",
|
"@vitejs/test-dep-with-builtin-module-cjs": "file:./dep-with-builtin-module-cjs",
|
||||||
|
@ -967,6 +967,9 @@ importers:
|
|||||||
'@vitejs/test-dep-relative-to-main':
|
'@vitejs/test-dep-relative-to-main':
|
||||||
specifier: file:./dep-relative-to-main
|
specifier: file:./dep-relative-to-main
|
||||||
version: file:playground/optimize-deps/dep-relative-to-main
|
version: file:playground/optimize-deps/dep-relative-to-main
|
||||||
|
'@vitejs/test-dep-source-map-no-sources':
|
||||||
|
specifier: file:./dep-source-map-no-sources
|
||||||
|
version: file:playground/optimize-deps/dep-source-map-no-sources
|
||||||
'@vitejs/test-dep-with-asset-ext1.pdf':
|
'@vitejs/test-dep-with-asset-ext1.pdf':
|
||||||
specifier: file:./dep-with-asset-ext/dep1
|
specifier: file:./dep-with-asset-ext/dep1
|
||||||
version: file:playground/optimize-deps/dep-with-asset-ext/dep1
|
version: file:playground/optimize-deps/dep-with-asset-ext/dep1
|
||||||
@ -1092,6 +1095,8 @@ importers:
|
|||||||
|
|
||||||
playground/optimize-deps/dep-relative-to-main: {}
|
playground/optimize-deps/dep-relative-to-main: {}
|
||||||
|
|
||||||
|
playground/optimize-deps/dep-source-map-no-sources: {}
|
||||||
|
|
||||||
playground/optimize-deps/dep-with-asset-ext/dep1: {}
|
playground/optimize-deps/dep-with-asset-ext/dep1: {}
|
||||||
|
|
||||||
playground/optimize-deps/dep-with-asset-ext/dep2:
|
playground/optimize-deps/dep-with-asset-ext/dep2:
|
||||||
@ -3344,6 +3349,9 @@ packages:
|
|||||||
'@vitejs/test-dep-self-reference-url-worker@file:playground/worker/dep-self-reference-url-worker':
|
'@vitejs/test-dep-self-reference-url-worker@file:playground/worker/dep-self-reference-url-worker':
|
||||||
resolution: {directory: playground/worker/dep-self-reference-url-worker, type: directory}
|
resolution: {directory: playground/worker/dep-self-reference-url-worker, type: directory}
|
||||||
|
|
||||||
|
'@vitejs/test-dep-source-map-no-sources@file:playground/optimize-deps/dep-source-map-no-sources':
|
||||||
|
resolution: {directory: playground/optimize-deps/dep-source-map-no-sources, type: directory}
|
||||||
|
|
||||||
'@vitejs/test-dep-that-imports@file:playground/external/dep-that-imports':
|
'@vitejs/test-dep-that-imports@file:playground/external/dep-that-imports':
|
||||||
resolution: {directory: playground/external/dep-that-imports, type: directory}
|
resolution: {directory: playground/external/dep-that-imports, type: directory}
|
||||||
|
|
||||||
@ -9005,6 +9013,8 @@ snapshots:
|
|||||||
|
|
||||||
'@vitejs/test-dep-self-reference-url-worker@file:playground/worker/dep-self-reference-url-worker': {}
|
'@vitejs/test-dep-self-reference-url-worker@file:playground/worker/dep-self-reference-url-worker': {}
|
||||||
|
|
||||||
|
'@vitejs/test-dep-source-map-no-sources@file:playground/optimize-deps/dep-source-map-no-sources': {}
|
||||||
|
|
||||||
'@vitejs/test-dep-that-imports@file:playground/external/dep-that-imports(typescript@5.6.3)':
|
'@vitejs/test-dep-that-imports@file:playground/external/dep-that-imports(typescript@5.6.3)':
|
||||||
dependencies:
|
dependencies:
|
||||||
slash3: slash@3.0.0
|
slash3: slash@3.0.0
|
||||||
|
Loading…
Reference in New Issue
Block a user