Skip to content

Instantly share code, notes, and snippets.

@boydaihungst
Last active May 2, 2021 02:17
Show Gist options
  • Save boydaihungst/5a273fed3fb6d01a808aacd2f4b76bdc to your computer and use it in GitHub Desktop.
Save boydaihungst/5a273fed3fb6d01a808aacd2f4b76bdc to your computer and use it in GitHub Desktop.
Use this file to generate alias.
const path = require('path');
const aliases = {
'@': '.',
'@src': './src',
'@router': './src/router',
'@views': './src/router/views',
'@layouts': './src/router/layouts',
'@components': './src/components',
'@assets': './src/assets',
'@utils': './src/utils',
'@state': './src/state',
// custom
'@plugin': './src/plugin',
'@graphql': './src/graphql',
'@api': './src/api',
'@models': './src/models',
};
module.exports = {
webpack: {},
};
for (const alias in aliases) {
const aliasTo = aliases[alias];
module.exports.webpack[alias] = resolveSrc(aliasTo);
}
console.log(module.exports);
/**
* this is the output. Just like webpack alias
* {@link https://webpack.js.org/configuration/resolve/#resolvealias}
* Then run command like "vue-int --output 'vetur' --input 'src/components' --recursive --alias aliases.config.js#webpack"
{
webpack: {
'@': '/home/boydaihungst/Gits/archived-file-frontend',
'@src': '/home/boydaihungst/Gits/archived-file-frontend/src',
'@router': '/home/boydaihungst/Gits/archived-file-frontend/src/router',
'@views': '/home/boydaihungst/Gits/archived-file-frontend/src/router/views',
'@layouts': '/home/boydaihungst/Gits/archived-file-frontend/src/router/layouts',
'@components': '/home/boydaihungst/Gits/archived-file-frontend/src/components',
'@assets': '/home/boydaihungst/Gits/archived-file-frontend/src/assets',
'@utils': '/home/boydaihungst/Gits/archived-file-frontend/src/utils',
'@state': '/home/boydaihungst/Gits/archived-file-frontend/src/state',
'@plugin': '/home/boydaihungst/Gits/archived-file-frontend/src/plugin',
'@graphql': '/home/boydaihungst/Gits/archived-file-frontend/src/graphql',
'@api': '/home/boydaihungst/Gits/archived-file-frontend/src/api',
'@models': '/home/boydaihungst/Gits/archived-file-frontend/src/models'
}
}
*/
function resolveSrc(_path) {
return path.resolve(__dirname, _path);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment