Vue-cli 生产环境配置

2017-11-02  本文已影响252人  TuoXiaozhong

基本思路

几个重要的配置

var path = require('path')
var express = require('express')
var config = require('../config')
var proxyMiddleware = require('http-proxy-middleware')

var port = process.env.PORT || config.dev.port
var proxyTable = config.dev.proxyTable

var app = express()

app.use(require('connect-history-api-fallback')())

Object.keys(proxyTable).forEach(function (context) {
  var options = proxyTable[context]
  if (typeof options === 'string') {
    options = { target: options }
  }
  app.use(proxyMiddleware(context, options))
})

app.use('/', express.static('./dist'))

if (process.env.NODE_ENV === 'production') {
    process.on('uncaughtException', function (err) {
        sentry.captureError(err);
    });
}

module.exports = app.listen(port, function (err) {
  if (err) {
    console.log(err)
    return
  }
  console.log('Listening at http://localhost:' + port + '\n')
})

{
  "apps": [
    {
      "name": "project_name",
      "script": "build/prod-server.js",
      "instances": "max",
      "log_date_format": "YYYY-MM-DD HH:mm Z",
      "max_memory_restart": "500M",
      "exec_mode": "cluster",
      "env": {
        "NODE_ENV": "production"
      }
    }
  ]
}
  "deploy": "cnpm install && node build/build.js && pm2 startOrRestart pm2.json"

说明

上一篇下一篇

猜你喜欢

热点阅读