Skip to content

Commit 9fdd0a3

Browse files
matthewppatak-dev
authored andcommitted
feat: backport treat Astro file scripts as TS (#8151)
1 parent 9fbc1a9 commit 9fdd0a3

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
type Foo = 'bar';
3+
console.log("stuff");
4+
</script>

packages/playground/optimize-deps/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ <h2>Reused variable names</h2>
119119

120120
import { parse } from 'node:url'
121121
text('.url', parse('https://vitejs.dev').hostname)
122+
123+
import './index.astro'
122124
</script>
123125

124126
<script type="module">

packages/playground/optimize-deps/vite.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ module.exports = {
5050
res.end('pong')
5151
})
5252
}
53+
},
54+
{
55+
name: 'test-astro',
56+
transform(code, id) {
57+
if (id.endsWith('.astro')) {
58+
code = `export default {}`
59+
return { code }
60+
}
61+
}
5362
}
5463
]
5564
}

packages/vite/src/node/optimizer/scan.ts

+2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ function esbuildScanPlugin(
281281
let loader: Loader = 'js'
282282
if (lang === 'ts' || lang === 'tsx' || lang === 'jsx') {
283283
loader = lang
284+
} else if (path.endsWith('.astro')) {
285+
loader = 'ts'
284286
}
285287
const srcMatch = openTag.match(srcRE)
286288
if (srcMatch) {

0 commit comments

Comments
 (0)