Created
October 21, 2018 17:14
-
-
Save vadim7j7/04d5c23289d67700088fe36692c5f281 to your computer and use it in GitHub Desktop.
Script watcher for react-create-app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// put it to scripts/watch.js | |
// add - "watch": "node scripts/watch.js", into package.json in section scripts | |
process.env.NODE_ENV = "development"; | |
const fs = require("fs-extra"); | |
const paths = require("react-scripts/config/paths"); | |
const webpack = require("webpack"); | |
const config = require("react-scripts/config/webpack.config.dev.js"); | |
// removes react-dev-utils/webpackHotDevClient.js at first in the array | |
config.entry.shift(); | |
config.output.path = __dirname + "../../../backend/public/"; | |
config.output.hotUpdateChunkFilename = 'hot/hot-update.json'; | |
config.output.hotUpdateMainFilename = 'hot/hot-update.json'; | |
webpack(config).watch({}, (err, stats) => { | |
if (err) { | |
console.error(err); | |
} else { | |
copyPublicFolder(); | |
} | |
console.error(stats.toString({ | |
chunks: false, | |
colors: true | |
})); | |
}); | |
function copyPublicFolder() { | |
fs.copySync(paths.appPublic, paths.appBuild, { | |
dereference: true, | |
filter: file => file !== paths.appHtml | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment