Skip to content

Commit

Permalink
feat: treat Astro file scripts as TS (#8151)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored May 13, 2022
1 parent 2289d04 commit 559c952
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ function esbuildScanPlugin(
let loader: Loader = 'js'
if (lang === 'ts' || lang === 'tsx' || lang === 'jsx') {
loader = lang
} else if (path.endsWith('.astro')) {
loader = 'ts'
}
const srcMatch = openTag.match(srcRE)
if (srcMatch) {
Expand Down
4 changes: 4 additions & 0 deletions playground/optimize-deps/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script>
type Foo = 'bar';
console.log("stuff");
</script>
2 changes: 2 additions & 0 deletions playground/optimize-deps/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ <h2>Reused variable names</h2>

import { parse } from 'node:url'
text('.url', parse('https://vitejs.dev').hostname)

import './index.astro'
</script>

<script type="module">
Expand Down
9 changes: 9 additions & 0 deletions playground/optimize-deps/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ module.exports = {
res.end('pong')
})
}
},
{
name: 'test-astro',
transform(code, id) {
if (id.endsWith('.astro')) {
code = `export default {}`
return { code }
}
}
}
]
}
Expand Down

0 comments on commit 559c952

Please sign in to comment.