From 9dfc83d88bd3b3c271b7bf2af7881946c0fbb60b Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 22 Jul 2022 01:24:20 +0800 Subject: [PATCH 1/2] fix(scan): handle .ts import as .js alias --- packages/vite/src/node/optimizer/scan.ts | 8 ++++++-- playground/vue/TsImport.vue | 4 +++- playground/vue/__tests__/vue.spec.ts | 1 + playground/vue/vite.config.ts | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index 5a6c55ea0a5746..2b87ccdcbcad54 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -379,14 +379,18 @@ function esbuildScanPlugin( // avoid matching windows volume filter: /^[\w@][^:]/ }, - async ({ path: id, importer }) => { + async ({ path: id, importer, pluginData }) => { if (moduleListContains(exclude, id)) { return externalUnlessEntry({ path: id }) } if (depImports[id]) { return externalUnlessEntry({ path: id }) } - const resolved = await resolve(id, importer) + const resolved = await resolve(id, importer, { + custom: { + depScan: { loader: pluginData?.htmlType?.loader } + } + }) if (resolved) { if (shouldExternalizeDep(resolved, id)) { return externalUnlessEntry({ path: id }) diff --git a/playground/vue/TsImport.vue b/playground/vue/TsImport.vue index 2b65011a160d23..776fb62acbf687 100644 --- a/playground/vue/TsImport.vue +++ b/playground/vue/TsImport.vue @@ -1,8 +1,10 @@ diff --git a/playground/vue/__tests__/vue.spec.ts b/playground/vue/__tests__/vue.spec.ts index 3b6e2cc15555b1..4a55bdfe80802f 100644 --- a/playground/vue/__tests__/vue.spec.ts +++ b/playground/vue/__tests__/vue.spec.ts @@ -25,6 +25,7 @@ test('template/script latest syntax support', async () => { test('import ts with .js extension with lang="ts"', async () => { expect(await page.textContent('.ts-import')).toBe('success') + expect(await page.textContent('.ts-import2')).toBe('success') }) test('should remove comments in prod', async () => { diff --git a/playground/vue/vite.config.ts b/playground/vue/vite.config.ts index f99a68ce8b6b10..c1561ce2c2bd47 100644 --- a/playground/vue/vite.config.ts +++ b/playground/vue/vite.config.ts @@ -5,7 +5,8 @@ import { vueI18nPlugin } from './CustomBlockPlugin' export default defineConfig({ resolve: { alias: { - '/@': __dirname + '/@': __dirname, + '@': __dirname } }, plugins: [ From 3d4c3ed956f01158ee5c38fbad38f3ce74e529ed Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 22 Jul 2022 02:04:56 +0800 Subject: [PATCH 2/2] chore: fix typo --- playground/vue/TsImport.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/vue/TsImport.vue b/playground/vue/TsImport.vue index 776fb62acbf687..7858c8cfa674d2 100644 --- a/playground/vue/TsImport.vue +++ b/playground/vue/TsImport.vue @@ -6,5 +6,5 @@