123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- // vue.config.js
- const path = require('path');
- const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV);
- const resolve = (dir) => path.join(__dirname, dir);
- const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); // 去掉 console.log
- module.exports = {
- publicPath: "./", // 默认'/',部署应用包时的基本 URL
- indexPath: 'index.html', // 相对于打包路径index.html的路径
- outputDir: 'dist', // 'dist', 生产环境构建文件的目录
- assetsDir: 'static', // 相对于outputDir的静态资源(js、css、img、fonts)目录
- lintOnSave: false, // 是否在开发环境下通过 eslint-loader 在每次保存时 lint 代码
- runtimeCompiler: true, // 是否使用包含运行时编译器的 Vue 构建版本
- productionSourceMap: !IS_PROD, // 生产环境的 source map
- chainWebpack: config => {
- config.resolve.symlinks(true); // 修复热更新失效
- // 添加别名
- config.resolve.alias
- .set('@', resolve('src'))
- .set('@api', resolve('src/api'))
- .set('@tools', resolve('src/tools'))
- .set('@assets', resolve('src/assets'))
- .set('@components', resolve('src/components'))
- .set('@views', resolve('src/views'))
- .set('@router', resolve('src/router'))
- .set('@store', resolve('src/store'))
- .set('@layout',resolve('src/layout'))
- .set('@utils',resolve('src/utils'))
- .set('@jsonData', resolve('src/jsonData'));
- // 压缩图片
- if (IS_PROD) {
- config.module
- .rule("images")
- .use("image-webpack-loader")
- .loader("image-webpack-loader")
- .options({
- mozjpeg: { progressive: true, quality: 65 },
- optipng: { enabled: false },
- pngquant: { quality: [0.65, 0.9], speed: 4 },
- gifsicle: { interlaced: false }
- // webp: { quality: 75 }
- });
- }
- },
- css: {
- loaderOptions: {
- sass: {
- prependData: `@import "./src/assets/css/default";`,
- },
- },
- },
- // 去掉console.log
- configureWebpack: config => {
- if (IS_PROD) {
- const plugins = [];
- plugins.push(
- new UglifyJsPlugin({
- uglifyOptions: {
- compress: {
- drop_console: true,
- drop_debugger: false,
- pure_funcs: ["console.log"] //移除console
- }
- },
- sourceMap: false,
- parallel: true
- })
- );
- config.plugins = [...config.plugins, ...plugins];
- }
- },
- devServer: {
- //代理配置
- proxy:{
- //这里的api表示请求的地址有apizzzs,就触发代理机制
- '/apizzz':{
- target:'www.baidu.com',//我们要代理的地址
- changeOrigin:true,//是否跨域
- pathRewrite:{
- //'^/api',''//假设想把 localhost:8080/api/login 变成www.baidu.com/login就需要这么做
- }
- }
- },
- open: true, // 是否打开浏览器
- }
- }
|