Skip to content

Export react-scripts functionality #781

Closed
@floriangosse

Description

@floriangosse

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions