vue-cli2和3中的config


最近在網上找了個vue搭建的后台管理的框架,在使用的時候發現沒有了config和build文件夾,所以當時就蒙圈了,以為是作者自己改了什么東西,所以感覺自己不知道從何下手了,不過通過查資料發現原來是vue-cli2和3的config不相同,vue-cli3更加簡潔了而已,vue.config.js是自己根據自己的需求新建的文件,開始是沒有的。

 

所以自己開始各種查資料去了解vue-cli3的vue.config.js中的配置項,最后總結下來的

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 => {}
  },
 
pages: {
 index: { // page 的入口 entry: 'src/index/main.js', // 模板來源 template: 'public/index.html', // 在 dist/index.html 的輸出 filename: 'index.html', // 當使用 title 選項時// template 中的 title 標簽需要是 <title><%= htmlWebpackPlugin.options.title %></title> title: 'Index Page', // 在這個頁面中包含的塊,默認情況下會包含 // 提取出來的通用 chunk 和 vendor chunk。 chunks: ['chunk-vendors', 'chunk-common', 'index'] }, // 當使用只有入口的字符串格式時, // 模板會被推導為 `public/subpage.html` // 並且如果找不到的話,就回退到 `public/index.html`。 // 輸出文件名會被推導為 `subpage.html`。 subpage: 'src/subpage/main.js' }
// 第三方插件配置 
pluginOptions: { // ... } }
//Vue.config.js配置跨域 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); });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM