vue-cli3.0相關的坑

vue-cli3.0相對比vue-cli2.0少了 vue-build.js vue-config.js html

vue-cli2.0 運行命令 npm run dev
vue-cli3.0 運行命令 npm run servevue

vue-cli3.0 要本身在項目根目錄下配置 vue-config.jsios

module.exports = {
  // baseUrl  type:{string} default:'/' 
  // 將部署應用程序的基本URL
  // 將部署應用程序的基本URL。
  // 默認狀況下,Vue CLI假設您的應用程序將部署在域的根目錄下。
  // https://www.my-app.com/。若是應用程序部署在子路徑上,則須要使用此選項指定子路徑。例如,若是您的應用程序部署在https://www.foobar.com/my-app/,集baseUrl到'/my-app/'.

  baseUrl: './',


  // outputDir: 在npm run build時 生成文件的目錄 type:string, default:'dist'

  outputDir: 'dist',

  // pages:{ type:Object,Default:undfind } 
/*
構建多頁面模式的應用程序.每一個「頁面」都應該有一個相應的JavaScript條目文件。該值應該是一
個對象,其中鍵是條目的名稱,而該值要麼是指定其條目、模板和文件名的對象,要麼是指定其條目
的字符串,
注意:請保證pages裏配置的路徑和文件名 在你的文檔目錄都存在 不然啓動服務會報錯的
*/
  // pages: {
      // index: {
          // entry for the page
          // entry: 'src/index/main.js',
          // the source template
          // template: 'public/index.html',
          // output as dist/index.html
          // filename: 'index.html'
      // },
      // when using the entry-only string format,
      // template is inferred to be `public/subpage.html`
      // and falls back to `public/index.html` if not found.
      // Output filename is inferred to be `subpage.html`.
      // subpage: 'src/subpage/main.js'
  // },

  //   lintOnSave:{ type:Boolean default:true } 問你是否使用eslint
  lintOnSave: true,
  // productionSourceMap:{ type:Bollean,default:true } 生產源映射
  // 若是您不須要生產時的源映射,那麼將此設置爲false能夠加速生產構建
  productionSourceMap: false,
  // devServer:{type:Object} 3個屬性host,port,https
  // 它支持webPack-dev-server的全部選項
 
  devServer: {

      port: 8085, // 端口號
      host: 'localhost',
      https: false, // https:{type:Boolean}
      open: true, //配置自動啓動瀏覽器
      // proxy: 'http://localhost:4000' // 配置跨域處理,只有一個代理
      proxy: {
          '/api': {
              target: 'https://apiv2.pinduoduo.com',
              ws: true,
              changeOrigin: true
          },
          '/foo': {
              target: '<other_url>'
          }
      },  // 配置多個代理
  }
}

vue在用HBuilder打包後 app啓動一片空白 3.0裏面的baseUrl 改爲 baseUrl: './'web

若是你安裝了vue-cli3.0卻要用cli2.0的話那麼你須要全局安裝一個橋接工具 npm install -g @vue/cli-init
另外使用HBuilder將項目打包的時候發現本身的接口裏面的數據請求不到,其它靜態資源正常顯示。那是由於在開發階段瀏覽器須要解決跨域問題使用了反向代理,若是打包app須要將代理註釋,axios請求地址改成絕對路徑vue-cli

相關文章
相關標籤/搜索