Skip to content

Instantly share code, notes, and snippets.

@davetorbeck
Created July 24, 2018 05:30
Show Gist options
  • Save davetorbeck/9be9eb09ab2063a32481d43a53cbd23e to your computer and use it in GitHub Desktop.
Save davetorbeck/9be9eb09ab2063a32481d43a53cbd23e to your computer and use it in GitHub Desktop.
Create-react-app script for watching live changes to build directory
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 = config.entry.filter(
entry => !entry.includes("webpackHotDevClient")
)
config.output.path = paths.appBuild
paths.publicUrl = paths.appBuild + "/"
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