npm run serve运行在公网

2021-08-25 11:03:55 阅读:1 编辑

pacage.json


{
  "name": "new_vue",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve  --disableHostCheck=true",
    "build": "vue-cli-service build"
  },
  "dependencies": {
    "@babel/plugin-transform-modules-commonjs": "^7.6.0",
    "animejs": "^3.1.0",
    "axios": "^0.19.0",
    "core-js": "^2.6.5",
    "jquery": "^3.4.1",
    "vant": "^2.1.8",
    "vconsole": "^3.3.4",
    "vue": "^2.6.10",
    "vue-qrcode-reader": "^2.3.0",
    "vue-router": "^3.0.3",
    "vuex": "^3.1.1",
    "weixin-js-sdk": "^1.4.0-test"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.10.0",
    "@vue/cli-service": "^3.10.0",
    "vue-template-compiler": "^2.6.10"
  }
}

vue.config.js

    devServer: {
        open: false,

        //host: '47.101.154.191',
        host:'0.0.0.0',
        port: 8081,

        https: false,

        hotOnly: false,
        public:'47.101.154.191',
        proxy: null,
        disableHostCheck: true,
        //allowedHosts: 'all',
        before: app => {
        }
    },

让npm run serve在Linux后台持久运行

如果你想记录日志文件【新建日志记录文件】

touch my.log
chmod u+w my.log
nohup npm run serve > my.log 2>my.log & exit

如果没有报错,就成功了。此时可以看到网页运行成功。

最后,一定要控制台执行exit,退出登录。

【不记录日志】

nohup npm run serve>/dev/null 2>&1 & exit