You can see example in the docs: https://router.vuejs.org/en/essentials/redirect-and-alias.html
Mar 9, 2018
7
Level 11
Vue and alias
Hi Everybody.
How can I have aliases in my vue files ? to prevent to use relative path everywhere ... That is not very convenient if I change the app structure in a future.
for example in my ./store/index.js I have in a function :
router.addRoutes([
{
path: '/clients',
component: require('../../views/Clients.vue')
}
]);
The best would be (as in Laravel) :
router.addRoutes([
{
path: '/clients',
component: require(views_path('/Clients.vue'))
}
]);
What is the best way to achieve that ?
Thanks for your help ! :)
Level 11
That's okay, in my webpack.mix.js file I've added this and that's works fine :
let src_path = 'resources/assets/js/';
mix.webpackConfig({
resolve: {
alias: {
'@src': path.resolve(__dirname, src_path),
'@store': path.resolve(__dirname, src_path + 'store/'),
'@views': path.resolve(__dirname, src_path + 'views/'),
'@components': path.resolve(__dirname, src_path + 'components/'),
'@modules': path.resolve(__dirname, src_path + '/modules/'),
}
}
});
``
Please or to participate in this conversation.