vue-cli3 中的一些相關配置

1.在一個vue-cli3項目中,須要兩個端口號,(vue-cli3,node服務) cnpm i concurrently -D 在package.json 中進行配置:css

"scripts": {
      "serve": "vue-cli-service serve",
      "build": "vue-cli-service build",
      "server": "nodemon server.js",
      "dev": "concurrently \"npm run serve\" \"npm run server\" "
  }
複製代碼

2.vue.config.js中的經常使用配置:vue

const path = require('path')
const appData = require("./data.json");
const seller = appData.seller;
const goods = appData.goods;
const ratings = appData.ratings;

module.exports = {
   configureWebpack: {
       resolve: {
           alias: {
               'components': path.join(__dirname, 'src/components')
           }
       }
   },
   css: {
       loaderOptions: {
           stylus: {
               import: ['~@/assets/style/index.styl', '~@/assets/style/demo.styl']
           }
       }
   },
   devServer: {  //跨域配置
       proxy: {
           '/api': {
               target: "http://localhost:8088/",
               ws: true,
               changOrigin: true,
               pathRewrite: {
                   '^/api': ''
               }
           }
       },
        before(app) { //mock數據的配置
           app.get('/api/seller', (req, res, next) => {
                   res.json({
                       errno: 0,
                       data: seller
                   });
               }),
               app.get('/api/goods', (req, res, next) => {
                   res.json({
                       errno: 0,
                       data: goods
                   });
               }),
               app.get('/api/ratings', (req, res, next) => {
                   res.json({
                       errno: 0,
                       data: ratings
                   });
               })
       }
   }
}
複製代碼

後續會持續更新,但願你們多多支持,多多給意見。學習筆記node

相關文章
相關標籤/搜索