From 559c95268a4fe051834efdb04854d5a4c5345124 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 12 May 2022 23:37:52 -0600 Subject: [PATCH] feat: treat Astro file scripts as TS (#8151) --- packages/vite/src/node/optimizer/scan.ts | 2 ++ playground/optimize-deps/index.astro | 4 ++++ playground/optimize-deps/index.html | 2 ++ playground/optimize-deps/vite.config.js | 9 +++++++++ 4 files changed, 17 insertions(+) create mode 100644 playground/optimize-deps/index.astro diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index 157c8d28db1083..6f609991ecc7fb 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -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) { diff --git a/playground/optimize-deps/index.astro b/playground/optimize-deps/index.astro new file mode 100644 index 00000000000000..95790f5bf3a0d5 --- /dev/null +++ b/playground/optimize-deps/index.astro @@ -0,0 +1,4 @@ + diff --git a/playground/optimize-deps/index.html b/playground/optimize-deps/index.html index d11383bfcb3e04..3cd619f9ce9236 100644 --- a/playground/optimize-deps/index.html +++ b/playground/optimize-deps/index.html @@ -119,6 +119,8 @@

Reused variable names

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