私はexpressを利用して反応するプロジェクトをセットアップしようとしています。そして私は可能な限り多くの利益を得るためにReact-Slingshotプロジェクトを最大限に活用しようとしています。しかし、問題は、私が書いたスクリプトでプロジェクトを(サーバー側で)提供する必要があることです。このスクリプトでは、クライアント側のサーバにexpressとおそらくsocket.ioを使用します。コンパイル、ウォッチ、サーバーのためのカスタマイズされたnpmスクリプト
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"
},
これは、あなたが反応-スリングショットで見つけることができるものの修正版です。私はnpm run build
を実行するときに変更を加えました。それはサーバーコードも構築して終了します。それはこのようにするために使用:
"build": "babel-node tools/build.js && npm run open:dist",
を今、コードの残りの部分は私のdevの環境用として--watch
に基づいてコンパイルされている間、私は(すなわちnode temp/server.js
)私自身のサーバを実行する方法を見つけようとしています。