mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
feat: sourcemap for importAnalysis (#8258)
This commit is contained in:
parent
95297dd184
commit
a4e4d39458
@ -15,7 +15,7 @@
|
||||
"scripts": {
|
||||
"preinstall": "npx only-allow pnpm",
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint packages/*/{src,types}/** playground/**/__tests__/** scripts/**",
|
||||
"lint": "eslint packages/*/{src,types}/** playground/**/__tests__/**/*.ts scripts/**",
|
||||
"typecheck": "tsc -p scripts --noEmit && tsc -p playground --noEmit",
|
||||
"test": "run-s test-unit test-serve test-build",
|
||||
"test-serve": "vitest run -c vitest.config.e2e.ts",
|
||||
|
@ -645,7 +645,10 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
|
||||
}
|
||||
|
||||
if (s) {
|
||||
return s.toString()
|
||||
return {
|
||||
code: s.toString(),
|
||||
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
||||
}
|
||||
} else {
|
||||
return source
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
const modules = import.meta.glob('./*.(js|ts)', { eager: true })
|
||||
const globWithAlias = import.meta.glob('@dir/al*.js', { eager: true })
|
||||
|
||||
// test for sourcemap
|
||||
console.log('hello')
|
||||
|
||||
export { modules, globWithAlias }
|
||||
|
@ -6,5 +6,8 @@ export default defineConfig({
|
||||
alias: {
|
||||
'@dir': path.resolve(__dirname, './dir/')
|
||||
}
|
||||
},
|
||||
build: {
|
||||
sourcemap: true
|
||||
}
|
||||
})
|
||||
|
@ -0,0 +1,25 @@
|
||||
// Vitest Snapshot v1
|
||||
|
||||
exports[`serve:vue-sourcemap > js 1`] = `
|
||||
{
|
||||
"mappings": "mIAKA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;AAGP;AACd,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;wBARlB,oBAAiB,WAAd,MAAU",
|
||||
"sources": [
|
||||
"/root/Js.vue",
|
||||
],
|
||||
"sourcesContent": [
|
||||
"<template>
|
||||
<p><js></p>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
console.log('script')
|
||||
</script>
|
||||
|
||||
<script setup>
|
||||
console.log('setup')
|
||||
</script>
|
||||
",
|
||||
],
|
||||
"version": 3,
|
||||
}
|
||||
`;
|
@ -22,29 +22,7 @@ describe.runIf(isServe)('serve:vue-sourcemap', () => {
|
||||
const res = await page.request.get(new URL('./Js.vue', page.url()).href)
|
||||
const js = await res.text()
|
||||
const map = extractSourcemap(js)
|
||||
expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
|
||||
{
|
||||
"mappings": "AAKA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;AAGP;AACd,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;wBARlB,oBAAiB,WAAd,MAAU",
|
||||
"sources": [
|
||||
"/root/Js.vue",
|
||||
],
|
||||
"sourcesContent": [
|
||||
"<template>
|
||||
<p><js></p>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
console.log('script')
|
||||
</script>
|
||||
|
||||
<script setup>
|
||||
console.log('setup')
|
||||
</script>
|
||||
",
|
||||
],
|
||||
"version": 3,
|
||||
}
|
||||
`)
|
||||
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('ts', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user