A vue-cli plugin that automatically sets aliases. According to the
rootDirName
and then auto generated directory alias
English | 中文
vue add vue-cli-plugin-auto-alias
or
vue add auto-alias
// vue.config.js
module.exports = {
pluginOptions: {
'vue-cli-plugin-auto-alias': {
// rooot dir for auto gen alias
rootDirName: 'src',
// letter-case
// support case: camelCase,capitalCase,constantCase,dotCase,headerCase,noCase,paramCase,pascalCase,pathCase,sentenceCase,snakeCase
// https://www.npmjs.com/package/change-case
case: 'pascalCase',
// custom alias
alias: {
// just like a normal resolve in Webpack
// test:path.resolve(__dirname,'test')
},
},
},
}
- If your directory structure as follows
|---node_modules
|---public
|---src/ # rootDir
--- assets/
--- components/
--- router/
--- store/
--- views/
--- custom-dir/
|--- package.json
|--- vue.config.js
- and the options as follows
// vue.config.js
module.exports = {
pluginOptions: {
'vue-cli-plugin-auto-alias': {
// rooot dir for auto generated alias
rootDirName: 'src',
// letter-case
// support case: camelCase,capitalCase,constantCase,dotCase,headerCase,noCase,paramCase,pascalCase,pathCase,sentenceCase,snakeCase
// https://www.npmjs.com/package/change-case
case: 'pascalCase',
// custom alias
alias: {
Public: path.resolve(__dirname, 'public'),
},
},
},
}
- and you will get webpack alias as follows
// vue inspect > output.js
{
resolve: {
alias: {
'@': 'D:\\Workspace\\web-front-report\\src',
vue$: 'vue/dist/vue.runtime.esm.js',
// according to the rootDirName auto generated alias
Assets: 'D:\\Workspace\\web-front-report\\src\\assets',
Components: 'D:\\Workspace\\web-front-report\\src\\components',
Router: 'D:\\Workspace\\web-front-report\\src\\router',
Store: 'D:\\Workspace\\web-front-report\\src\\store',
CustomDir: 'D:\\Workspace\\web-front-report\\src\\custom-dir',
// custom alias
Public: 'D:\\Workspace\\web-front-report\\public
},
}
Give a ⭐️ if this project helped you!
Copyright © 2020 [email protected].
This project is MIT licensed.
Thanks goes to these wonderful people (emoji key):
GuangHui 📆 |
This project follows the all-contributors specification. Contributions of any kind welcome!