question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Export react-scripts functionality

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
floriangossecommented, Sep 27, 2016

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).

0reactions
gaearoncommented, Sep 27, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to export component in react js to use in another project?
I make a simple component hello world in react js this import React from 'react'; function App() { return ( <div > hello4...
Read more >
ReactJS | Importing and Exporting - GeeksforGeeks
Importing is possible only if the module or named property to be imported has been exported in its declaration. In React we use...
Read more >
Code-Splitting - React
Named Exports​​ React.lazy currently only supports default exports. If the module you want to import uses named exports, you can create an intermediate...
Read more >
The React Scripts Start Command – Create-React-App NPM ...
The script generates the required files and folders to start the React application and run it on the browser. This allows you to...
Read more >
Export React Components as Node Modules to NPM
If you have been developing reusable components in React for your projects, an efficient approach for development is publishing them to npm ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found