我正在尝试建立一个使用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编译的。
https://stackoverflow.com/questions/47685509
复制相似问题