1.0.2 • Published 2 months ago
vue-cli-plugin-inject-alias v1.0.2
English | 简体中文
vue-cli-plugin-inject-alias
基于路径自动生成别名
特性
- 支持别名自定义
- 支持同步模式自定义配置
安装
with pnpm
pnpm add vue-cli-plugin-inject-alias -D
with yarn
yarn add vue-cli-plugin-inject-alias -D
with npm
npm install vue-cli-plugin-inject-alias -D
with vue
vue add vue-cli-plugin-inject-alias
配置项
export interface AutoAlias {
/**
* @description 别名生成的路径
* @default src
*/
root?: string;
/**
* @description 别名前缀
* @default @
*/
prefix?: string;
/**
* @description json同步模式
* @default all
*/
mode?: 'sync' | 'off';
/**
* @description 别名配置文件路径
* @default tsconfig.json
*/
aliasPath?: string;
}
关于 mode
- sync : 当使用
sync
时,插件会在当前项目的根目录中搜索tsconfig.json
或jsconfig.json
,因此请确保该文件存在于项目中。该插件将在运行时自动生成paths
选项,然后将它们写入文件,而无需开发人员手动添加
vue.config.js
const { resolve } = require('path');
module.exports = defineConfig({
// other config
transpileDependencies: true,
pluginOptions: {
'vue-cli-plugin-inject-alias': {
mode: 'sync',
prefix: '@',
root: resolve(__dirname, './src'),
aliasPath: path.resolve(__dirname, './tsconfig.json')
}
}
});
tsconfig.json / jsconfig.json
{
"compilerOptions": {
"baseUrl": "./"
// ...
}
}
example
|-- src
|-- plugins
|-- router
|-- scss
|-- store
|-- utils
|-- views
|-- ....
import xxx from '@plugins/xxx';
import xxx from '@router/xxx';
import xxx from '@scss/xxx';
import xxx from '@store/xxx';
import xxx from '@utils/xxx';
import xxx from '@views/xxx';
....
1.0.2
2 months ago
1.0.1
2 months ago
1.0.0
3 months ago
0.0.19
3 months ago
0.0.17
6 months ago
0.0.18
5 months ago
0.0.11
10 months ago
0.0.12
9 months ago
0.0.14
9 months ago
0.0.15
8 months ago
0.0.16
8 months ago
0.0.9
1 year ago
0.0.8
1 year ago
0.0.5
1 year ago
0.0.4
1 year ago
0.0.7
1 year ago
0.0.6
1 year ago
0.0.3
1 year ago
0.0.2
1 year ago