为什么 npm run serve 在 Vue.js 上构建速度很慢?

ffb*_*ord 5 javascript node.js vue.js

我在 Vue.js 上有一个项目,我运行npm run serve来设置服务器。尽管直到一个小时前这还可以正常工作,但突然间我的项目需要很长时间才能构建,更具体地说,它在 32% 上停留了超过 5 分钟。有谁知道我需要做什么才能解决这个问题?我不确定我需要上传哪些文件才能解决这个问题,但这是我的package.json文件:

{
  "name": "web",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "jwt-decode": "^2.2.0",
    "password-validator": "^4.1.1",
    "vue": "^2.5.22",
    "vue-cookies": "^1.5.12",
    "vue-router": "^3.0.1",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.4.0",
    "@vue/cli-plugin-eslint": "^3.4.0",
    "@vue/cli-service": "^3.4.0",
    "axios": "^0.18.0",
    "babel-eslint": "^10.0.1",
    "eslint": "^5.8.0",
    "eslint-plugin-vue": "^5.0.0",
    "vue-cli-plugin-axios": "0.0.4",
    "vue-template-compiler": "^2.5.21",
    "webpack-dev-server": "^3.1.14"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "rules": {},
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },
  "postcss": {
    "plugins": {
      "autoprefixer": {}
    }
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}
Run Code Online (Sandbox Code Playgroud)

Ivá*_*hez 0

如果您使用的是 Ubuntu(或者如果您是使用 Ubuntu 时面临此问题的其他用户)。可能是您的系统上没有足够的内存。您可以尝试添加 swap 内存,它可能会有所帮助。另外,如果您在服务器中遇到此问题,您应该考虑构建项目。

如果您使用其他操作系统,我不知道会发生什么。尝试删除node_modules目录并重新安装依赖项。