Vue-cli3 項目配置 Vue.config.js( 代替vue-cli2 build config)

Vue-cli3 搭建的項目 界面相對以前較爲簡潔css

以前的build和config文件夾不見了,那麼應該如何配置 如webpack等的配那html

只須要在項目的根目錄下新建 vue.config.js 文件(是根目錄,不是src目錄)vue

語法webpack

module.exports = {
  // 基本路徑 baseURL已通過時
  publicPath: './',  
  // 輸出文件目錄
  outputDir: 'dist',
  // eslint-loader 是否在保存的時候檢查
  lintOnSave: true,
  // use the full build with in-browser compiler?
  // https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
  // compiler: false,
  // webpack配置
  // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  chainWebpack: () => {},
  configureWebpack: () => {},
  // vue-loader 配置項
  // https://vue-loader.vuejs.org/en/options.html
  // vueLoader: {},
  // 生產環境是否生成 sourceMap 文件
  productionSourceMap: true,
  // css相關配置
  css: {
   // 是否使用css分離插件 ExtractTextPlugin
   extract: true,
   // 開啓 CSS source maps?
   sourceMap: false,
   // css預設器配置項
   loaderOptions: {},
   // 啓用 CSS modules for all css / pre-processor files.
   modules: false
  },
  // use thread-loader for babel & TS in production build
  // enabled by default if the machine has more than 1 cores
  parallel: require('os').cpus().length > 1,
  // 是否啓用dll
  // See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#dll-mode
  // dll: false,
  // PWA 插件相關配置
  // see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
  pwa: {},
  // webpack-dev-server 相關配置
  devServer: {
   open: process.platform === 'darwin',
   host: '0.0.0.0',//若是是真機測試,就使用這個IP
   port: 1234,
   https: false,
   hotOnly: false,
   proxy: null, // 設置代理
   before: app => {}
  },
  // 第三方插件配置
  pluginOptions: {
   // ...
  }
 }

Vue.config.js配置跨域git

devServer: {
        open: true, //瀏覽器自動打開頁面
        host: "0.0.0.0", //若是是真機測試,就使用這個IP
        port: 8911,
        https: false,
        hotOnly: false, //熱更新(webpack已實現了,這裏false便可)
        proxy: {
            //配置跨域
            '/api': {
                target: "http://192.168.234.237:8886/api",
                ws:true,
                changOrigin:true,
                pathRewrite:{
                    '^/api':'/'
                }
            }
        }
    }
//調用
this.$http.get('/api/order/getOrder')
        .then(res => {
          console.log(res.data);
        })
        .catch(err => {
          console.log(err.data.message);
        });
相關文章
相關標籤/搜索