Last active
March 2, 2019 14:19
-
-
Save bfocht/a0def4432d0f93dc28bc7cf64ebe8be1 to your computer and use it in GitHub Desktop.
post build script for create-react-app to move the js to a dist folder
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
const fs = require('fs'); | |
const file = require('./build/asset-manifest.json')['main.js']; | |
const src = './build/'; | |
const dest = './dist/'; | |
if (!fs.existsSync(dest)){ | |
fs.mkdirSync(dest); | |
} | |
if (fs.existsSync(dest+'index.js')){ | |
fs.unlinkSync(dest+'index.js'); | |
} | |
// remove source maps from production and move file to dist folder | |
fs.readFile(src+file, 'utf8', (err, data) => { | |
if (err) { | |
console.log('Unable to read file from manifest.'); | |
process.exit(1); | |
} | |
let version = `/*!\n* domain-search v${process.env.npm_package_version}\n* Licensed under MIT\n* \n*/\n`; | |
let result = data.split('//# sourceMappingURL'); | |
if (result[result.length - 1] !== undefined && result.length > 1) { | |
fs.writeFileSync(dest + 'index.js', version); | |
fs.appendFileSync(dest + 'index.js', result.slice(0, result.length - 1)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please also add little instructions on how can this be used?