Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scan): handle .ts import as .js alias #9282

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { vueI18nPlugin } from './CustomBlockPlugin'
export default defineConfig({
resolve: {
alias: {
'/@': __dirname
'/@': __dirname,
'@': __dirname
}
},
plugins: [
Expand Down