Skip to content

Instantly share code, notes, and snippets.

@howardjones
Forked from bfocht/postbuild.js
Last active January 17, 2018 11:26
Show Gist options
  • Save howardjones/5d581d6a46d50a4b49956aa89ed8842e to your computer and use it in GitHub Desktop.
Save howardjones/5d581d6a46d50a4b49956aa89ed8842e to your computer and use it in GitHub Desktop.
post build script for create-react-app to move the js to a dist folder
// Taken almost verbatim from https://gist.github.com/bfocht/a0def4432d0f93dc28bc7cf64ebe8be1
// copy the just-built js code into the place weathermap/cacti expect to find it
const fs = require('fs');
const src = './build/';
const dest = '../../cacti-resources/user/';
const targets = ["main.js", "main.css"];
for (let target of targets) {
let file = require('./build/asset-manifest.json')[target];
console.log(`${src}${file} => ${dest}${target}`);
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest);
}
if (fs.existsSync(dest + target)) {
fs.unlinkSync(dest + target);
}
// took out the map-stripping, but kept the read/write (vs copy) so that similar processing is easy to add
fs.readFile(src + file, 'utf8', (err, data) => {
if (err) {
console.log('Unable to read file from manifest.');
process.exit(1);
}
fs.writeFileSync(dest + target, data);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment