vue.config.js配置

本文详细介绍了如何使用vue.config.js文件来配置Vue.js项目,包括路径设置、环境变量、Webpack链式调用、公共路径调整、样式加载选项、依赖预编译及开发服务器代理配置等,为开发者提供全面的项目优化方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// vue.config.js
const path = require('path');
const config = require('./src/config/server');
const DIST_PATH = path.resolve(__dirname, './dist');
const DEBUG = process.env.NODE_ENV === 'development';
module.exports = {
  indexPath: DEBUG ? 'index.html' : 'index.ftl',
  chainWebpack: config => {
    config.plugin('html').tap(args => {
      args[0].csrf =
        '<meta name="_csrf" content="{{ctx.session.csrfToken}}"/><meta name="_csrf_header" content="X-CSRF-TOKEN"/>'
      return args
    })
    config.module.rule('eslint').use('eslint-loader').loader('eslint-loader').tap(options => {
      options.fix = true
      return options
    })
  },
  // publicPath: process.env.NODE_ENV === 'production' ? '/ctm01boss-web/' : '/',
  publicPath: DEBUG ? '/' : `${config.apiPathPrefix}`,
  outputDir: DIST_PATH,
  css: {
    loaderOptions: {
      less: {
        javascriptEnabled: true
      }
    }
  },
  transpileDependencies: [/@hui-pro/],
  devServer: {
    contentBase: DIST_PATH,
    compress: false,
    noInfo: true,
    host: '0.0.0.0',
    port: 8080,
    overlay: {
      warnings: false,
      errors: true
    },
    // open: true, //配置自动启动浏览器
    proxy: {
      [`${config.baseContext}/*`]: {
        target: config.target,
        secure: false,
        changeOrigin: true,
        onProxyReq: (proxyReq, req, res) => {
          if (config.isDev) {
            proxyReq.setHeader('Cookie', config.Cookie)
          }
        }
      }
    }
  }
};

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值