主要注意tsconfig, 结合vite配置别名
{
"compilerOptions": {
......
"baseUrl": "./",
......
"paths": {
"@": ["./src"],
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "src/**/*.js"],
"references": [{ "path": "./tsconfig.node.json" }]
}
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import Components from "unplugin-vue-components/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
const pathSrc = path.resolve(__dirname, 'src')
export default defineConfig({
base: process.env.NODE_ENV === "development" ? "/" : "./",
resolve: {
alias: [
{
find: "@",
replacement: path.resolve(__dirname, "src"),
},
],
},
css: {
preprocessorOptions: {
scss: {
charset: false,
additionalData: `@import './src/styles/index.scss';`,
},
},
},
build: {
reportCompressedSize: false,
chunkSizeWarningLimit: 2000,
},
plugins: [
vue(),
Components({
resolvers: [NaiveUiResolver()],
dts: path.resolve(pathSrc, 'components.d.ts'),
})
],
});