Skip to content

Commit

Permalink
fix(scan): handle .ts import as .js alias (#9282)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jul 21, 2022
1 parent 881050d commit 0b083ca
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions packages/vite/src/node/optimizer/scan.ts
Expand Up @@ -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 })
Expand Down
4 changes: 3 additions & 1 deletion playground/vue/TsImport.vue
@@ -1,8 +1,10 @@
<template>
<h2>Ts Import</h2>
<p class="ts-import">{{ foo }}</p>
<p class="ts-import2">{{ foo2 }}</p>
</template>

<script setup lang="ts">
import { foo } from '/@/TsImportFile.js'
import { foo } from '@/TsImportFile.js'
import { foo as foo2 } from '/@/TsImportFile.js'
</script>
1 change: 1 addition & 0 deletions playground/vue/__tests__/vue.spec.ts
Expand Up @@ -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 () => {
Expand Down
3 changes: 2 additions & 1 deletion playground/vue/vite.config.ts
Expand Up @@ -5,7 +5,8 @@ import { vueI18nPlugin } from './CustomBlockPlugin'
export default defineConfig({
resolve: {
alias: {
'/@': __dirname
'/@': __dirname,
'@': __dirname
}
},
plugins: [
Expand Down

0 comments on commit 0b083ca

Please sign in to comment.