Vue.js - 使用 WebPack 配置自定义别名

Vue.js - Configure a custom alias using WebPack

我正在尝试创建自定义别名,但出现错误:

Invalid options in vue.config.js: "resolve" is not allowed

这就是我所做的:

vue.config.js 用于 vue 配置 webpack 你需要用 [=] 包装你的 resolve 13=] 或 chainWebpack,类似于:

// vue.config.js
const path = require('path');
module.exports = {
  configureWebpack: {
    resolve: {...you config...}
  }
}

configureWebpack 也可以是一个函数,来自文档:

If you need conditional behavior based on the environment, or want to directly mutate the config, use a function (which will be lazy evaluated after the env variables are set). The function receives the resolved config as the argument. Inside the function, you can either mutate the config directly, OR return an object which will be merged: