自动注入 Less 全局变量
webpack
javascript
module.exports = defineConfig({
// 打包时自动移除console webpack 默认安装了 terser
transpileDependencies: true,
terser: {
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}
},
// 自动注入 Less 全局变量
css: {
loaderOptions: {
less: {
additionalData: '@import "~@/var.less"'
}
}
}
})vite esbulid rollup
javascript
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'~@': './src'
}
},
build: {
// 打包时自动移除console vite 需要安装 terser,先安装开发依赖
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}
},
// 自动注入 Less 全局变量
css: {
preprocessOptions: {
less: {
additionalData: '@import "~@/var.less"'
}
}
},
server: {
proxy: {
'/page': {
target: 'http://www.baidu.com/api/', // 目标服务器地址
changeOrigin: true, // 启用代理时,改变源地址
headers: {
Authorization: 'bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAi' //设置请求报头
}
}
}
}
/**
* 调用方法:
*
* axios
* .post('http://localhost:5173/page', {
* headers: {
* 'Content-Type': 'application/json'
* }
* })
* .then((data: any) => {
* console.log(data)
* })
*
* 相当于请求了后端服务接口:`http://www.baidu.com/api/page`
*/
})