【问题标题】:A customized npm script to compile, watch and server用于编译、监视和服务器的定制 npm 脚本
【发布时间】:2017-12-07 08:40:35
【问题描述】:

我正在尝试建立一个使用 express 和 react 的项目。我正在努力充分利用React-Slingshot 项目以尽可能地从中受益。但问题是我的项目需要(在服务器端)由我编写的脚本提供服务。该脚本将使用 express 和可能的 socket.io 来为客户端提供服务。

如果我使用像 React-Slingshot 这样的项目,我认为这是一个问题,因为它们带有自己的支持热重载和东西的服务器脚本。我愿意放弃像热重载这样的花哨功能。但我需要保留--watch 功能,因此每次更改某些文件时,无需我重新启动整个服务器即可编译代码。

现在,package.json 的脚本部分如下所示:

  "scripts": {
    "preinstall": "node tools/nodeVersionCheck.js",
    "setup": "node tools/setup/setupMessage.js && npm install && node tools/setup/setup.js",
    "remove-demo": "babel-node tools/removeDemo.js",
    "start-message": "babel-node tools/startMessage.js",
    "prestart": "npm run start-message",
    "start": "concurrently -k -r -s first \"npm run test:watch\" \"npm run open:src\" \"npm run lint:watch\"",
    "open:src": "babel-node tools/srcServer.js",
    "open:dist": "babel-node tools/distServer.js",
    "lint": "esw webpack.config.* src tools --color",
    "lint:watch": "npm run lint -- --watch",
    "clean-dist": "npm run remove-dist && mkdir dist",
    "remove-dist": "rimraf ./dist",
    "prebuild": "npm run clean-dist && npm run lint && npm run test",
    "build": "babel-node tools/build.js && babel server -d dist --presets es2015,stage-2",
    "test": "jest",
    "test:CI": "babel-node tools/testCi.js",
    "test:cover": "npm run test -- --coverage ",
    "test:cover:CI": "npm run test:CI -- --coverage && cat ./coverage/lcov.info | node_modules/coveralls/bin/coveralls.js",
    "test:watch": "jest --watch",
    "open:cover": "npm run test:cover && opn ./coverage/lcov-report/index.html",
    "analyze-bundle": "babel-node ./tools/analyzeBundle.js"
  },

这是您可以在 React-Slingshot 中找到的修改版本。我进行了更改,因此当我运行npm run build 时,它也会构建服务器代码并终止。以前是这样的:

   "build": "babel-node tools/build.js && npm run open:dist",

现在,我正在尝试找到一种方法来运行我自己的服务器(即node temp/server.js),而其余代码是基于--watch 编译的,就像我的开发环境一样。

【问题讨论】:

    标签: express npm webpack


    【解决方案1】:

    我相信您需要像watch 这样的包,也请查看this video

    【讨论】:

      猜你喜欢
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多