美文网首页工作生活
vue-cli 3.x 配置文件 vue.config.js

vue-cli 3.x 配置文件 vue.config.js

作者: 叶叶叶xxx | 来源:发表于2019-06-30 00:47 被阅读0次

新建一个vue.config.js放在项目文件夹中
webpack中文网 : https://webpack.docschina.org/configuration/

//vue.config.js
// const data = require('数据路径')

module.exports = {
  publicPath: '/', // 根路径
  outputDir: 'dist', // 构建输出目录
  assetsDir: 'assets', // 静态资源目录(js,css,img,fonts)
  lintOnSave: false, // 是否开启eslint保存检测,有效值(true||false||error)
  devServer: {
    open: false, // 有效值(true||false) npm run serve后,是否打开浏览器
    host: 'localhost', // 配置端口号
    port: 8080,
    https: false, // 有效值(true||false)
    hotOnly: false, // 热更新
    proxy: {
      // 配置跨域
      '/api': {
        target: '',
        ws: true, // 是否跨域
        changeOrigin: true,
        // 重写地址
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  },
  // 在服务内部的所有其他中间件之前, 提供执行自定义中间件的功能。 这可以用来配置自定义处理程序
  before (app) {
    //   加载本地数据
    // app.get('api/data', (req, res) => {
    //   res.json()
    // })
    // 在浏览器输入localhost:8080/api/data就可以拿到数据了
  }
}

相关文章

网友评论

    本文标题:vue-cli 3.x 配置文件 vue.config.js

    本文链接:https://www.haomeiwen.com/subject/qfxvcctx.html