xiaodongxier / iWebs

开发技术转载
https://github.xiaodongxier.com/iWebs
33 stars 8 forks source link

vue.config.js config.resolve.alias 目录别名配置 - 一丝心情 - 博客园 #198

Open xiaodongxier opened 1 year ago

xiaodongxier commented 1 year ago

'use strict' const path = require('path'); function resolve(dir) { return path.join(__dirname, dir) }

module.exports = { indexPath: "index.html", devServer: {}, // ... configureWebpack: { resolve: { alias: { '@': resolve('src'), //本项目路径src路径设置别名为@ 'assets': resolve('src/assets'), //本项目路径src/assets路径设置别名为assets,静态文件前要加~,否则只会以当前目录为基准 '$s': path.resolve(dirname, '../static/'), //项目根路径同级static目录设置别名为$$ '$@': path.resolve(dirname, '../static/src/') //项目根路径同级static/src目录设置别名为$@ } } }, / //或者也可以这么配置 chainWebpack: config => { config.resolve.alias .set('@', resolve('src')) //本项目路径src路径设置别名为@ .set('assets', resolve('src/assets')) //本项目路径src/assets路径设置别名为assets,静态文件前要加~,否则只会以当前目录为基准 .set('$s', path.resolve(dirname, '../static/')) //项目根路径同级static目录设置别名为$$ .set('$@', path.resolve(dirname, '../static/src/')) //项目根路径同级static/src目录设置别名为$@ } / }