标题重写如下:遇到同一文件夹中存在index.vue文件时,在Vue 3和Vite中使用无文件扩展名导入index.ts文件时会产生错误链接
P粉194919082
P粉194919082 2023-08-14 12:39:38
[Vue.js讨论组]

如何在同一个文件夹中有另一个index.vue文件的情况下,使用vue 3和vite导入index.ts文件而不指定文件扩展名?

我正在尝试导入组件:

import { Component } from '@/app/some_component'
src
|
└───
    app
    │   
    └───some_component
         │   index.ts
         │   index.vue
         │   ...

但是Webstorm默认引用index.vue文件。

所以,如何让Webstorm默认导入index.ts文件?

P.S. 顺便说一下,当我构建应用程序时一切正常,这似乎是Webstorm的链接问题。

这是vite.config.ts的内容

import { defineConfig } from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
  plugins: [vue(), tsconfigPaths()],
  server: {
    host: true,
    port: 5000,
  },
  preview: {
    port: 8000
  },
  resolve: {
    alias:
      {
        '@': path.resolve(__dirname, "./src"),
      },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `
        @import "@/app/styles/vars.scss";
        @import "@/app/styles/mixins.scss";
        `
      }
    }
  },
})

这是tsconfig.json的内容

{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve",

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx"],
  "references": [{ "path": "./tsconfig.node.json" }]
}


P粉194919082
P粉194919082

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号