Created
July 24, 2018 05:30
-
-
Save davetorbeck/9be9eb09ab2063a32481d43a53cbd23e to your computer and use it in GitHub Desktop.
Create-react-app script for watching live changes to build directory
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
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