Skip to content

Commit

Permalink
feat: backport treat Astro file scripts as TS (#8151)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and patak-dev committed Jun 6, 2022
1 parent 9fbc1a9 commit 9fdd0a3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/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 packages/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 packages/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
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 @@ -281,6 +281,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

0 comments on commit 9fdd0a3

Please sign in to comment.