Export react-scripts functionality
See original GitHub issueI started thinking about how I can extend the existing react-scripts functionality. E.g. I want to add some additional webpack plugins. I saw that #419 is the good move into an extendable system. But instead of forking react-scripts I want to extends or wrap it and benefit from the existing scripts.
My idea is to wrap the execution of the script in a function and pass the config and paths from outside:
function main (config, paths) {
// ... build
}
This makes it possible to load the config and execute the script directly …
if (require.main === module) {
var config = require('./path/to/config');
var paths = require('./path/to/paths');
main(config, paths);
}
… or export the main function.
// ...
else {
module.exports = main;
}
With this structure everyone can execute the script or use it like a library to provide own scripts.
I created a pull request (#776) with a few changes which make it possible to use it like a library. If someone want to checkout the code and has some hints what could be better feel free to let there a comment. 😃
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Yes, the more I think about it I think it is not so useful and makes react-scripts more complicated and harder to maintain.
Thank you for you time. And thank you for your great work (not only for create-react-app).
I think you might have better luck with an approach like this custom-react-scripts. Merging Webpack configs seems somewhat unsafe because we might move them or otherwise change them in incompatible ways.