数据关闭时,npm run watch不编译

时间:2019-03-21 22:58:48

标签: javascript node.js npm laravel-5.8

我正在与laravel一起工作,并使用了大量的节点包进行开发。 但是我的问题是我的互联网连接受到限制。

因此,每当我运行npm run watch时,它都不会启动,直到我连接到互联网为止。几个小时后,如果断开数据连接,它将停止编译。我在Windows机器上。

我的问题是,我有什么办法可以使编译工作在离线模式下进行?

还是我做错了什么? 我目前正在研究laravel 5.8

下面是我的package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.18",
        "bootstrap": "^4.0.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.5",
        "popper.js": "^1.12",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0",
        "vue": "^2.5.17",
        "vue-template-compiler": "^2.6.10"
    },
    "dependencies": {
        "@fortawesome/fontawesome-free": "^5.8.0",
        "admin-lte": "^3.0.0-alpha.2"
    }
}

1 个答案:

答案 0 :(得分:1)

这是一个在线版本,但是您可以将此脚本添加到package.json文件中

"watch": "webpack --watch --mode development",

这样,您可以避免执行期间不必要的资源和操作。 看起来像这样:

{
  "name": "watch",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.config.js",
  "scripts": {
    "watch": "webpack --watch  --mode development",
    "build": "webpack --mode production"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^4.16.5",
    "webpack-cli": "^3.1.0"
  }
}

有关更多信息,请参见: https://jscraftsman.com/2018/08/15/setting-up-the-javascript-development-environment/

https://gist.github.com/jscraftsman/17f968a26340b01176ee71a724bcb914#file-package-json

https://blog.fellyph.com.br/javascript/webpack-mantendo-a-qualidade-do-seu-javascript/