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

feat: sourcemap for importAnalysis #8258

Merged
merged 3 commits into from May 21, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions playground/glob-import/dir/index.js
@@ -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 }
3 changes: 3 additions & 0 deletions playground/glob-import/vite.config.ts
Expand Up @@ -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>&lt;js&gt;</p>
</template>

<script>
console.log('script')
</script>

<script setup>
console.log('setup')
</script>
",
],
"version": 3,
}
`;
24 changes: 1 addition & 23 deletions playground/vue-sourcemap/__tests__/serve.spec.ts
Expand Up @@ -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>&lt;js&gt;</p>
</template>

<script>
console.log('script')
</script>

<script setup>
console.log('setup')
</script>
",
],
"version": 3,
}
`)
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot()
})

test('ts', async () => {
Expand Down