Vue CLI4 configuration file path alias

Posted May 27, 20201 min read

Add vue.config.js to the project root directory

const path = require('path'); //Introduce the path module
function resolve(dir) {
    return path.join(__ dirname, dir) //path.join(__ dirname) set the absolute path
}
module.exports = {
    chainWebpack:config => {
        config.resolve.alias
        .set("@", resolve("src"))
        .set("assets", resolve("src/assets"))
        .set("components", resolve("src/components"))
        .set("views", resolve("src/views"));
        //set first parameter:set alias, second parameter:set path

    }
}