Skip to content

Commit

Permalink
📃 docs(docs-01-star): 补全路径别名。
Browse files Browse the repository at this point in the history
  • Loading branch information
ruan-cat committed Oct 26, 2024
1 parent daac8d0 commit 51511b2
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/docs-01-star/docs/09oa/frontend-architecture/vite.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ function pathResolve(dir: string) {

:::

## 路径别名

对常见的文件夹做路径别名设置,避免导入文件时过于冗长:

::: details 路径别名

<<< ./vite/resolve.ts

:::

与此同时,tsconfig.json 也要同步地做出改动:

在我们项目内,负责客户端的是 tsconfig.app.json 文件。

::: details tsconfig.app.json

<<< ./vite/examlpe-tsconfig.json

:::

## 插件

vite 插件配置是麻烦且复杂的。上限很高,完全取决于你自己对此的投入。
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "preserve",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"types": [
/** https://juejin.cn/post/7262322846252613693 */
"element-plus/global",
"vite/client",
"unplugin-auto-import",
/** https://uvr.esm.is/introduction.html#setup */
"unplugin-vue-router/client"
],
"allowJs": true,
"baseUrl": ".",
"paths": {
"@/*": [
"src/*"
],
"components/*": [
"src/components/*"
],
"types/*": [
"src/types/*"
],
"views/*": [
"src/views/*"
],
"api/*": [
"src/apis/*"
],
"stores/*": [
"src/stores/*"
],
"routers/*": [
"src/routers/*"
],
"utils/*": [
"src/utils/*"
],
"models/*": [
"src/models/*"
],
},
},
"include": [
"src",
// 导入全部的类型文件包括:
/**
auto-imports.d.ts
components.d.ts
typed-router.d.ts
*/
"types",
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
// 测试文件集
"tests/**/*.ts",
],
"exclude": [
"node_modules",
"dist",
"public",
"src/assets"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const resolve = {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
components: fileURLToPath(new URL("./src/components", import.meta.url)),
types: fileURLToPath(new URL("./src/types", import.meta.url)),
views: fileURLToPath(new URL("./src/views", import.meta.url)),
api: fileURLToPath(new URL("./src/apis", import.meta.url)),
stores: fileURLToPath(new URL("./src/stores", import.meta.url)),
router: fileURLToPath(new URL("./src/router", import.meta.url)),
utils: fileURLToPath(new URL("./src/utils", import.meta.url)),
models: fileURLToPath(new URL("./src/models", import.meta.url)),
},
};

0 comments on commit 51511b2

Please sign in to comment.