Crate build_my_react_js

Source
Expand description

This goes in your build script, for use with react-scripts, and cra template projects.

It can be helpful for both development and deployment.

So, as an example:

with the directory structure like

.gitignore
src/
my-frontend/
  src/
    index.js
  package.json
Cargo.toml
// `build.rs` see The Cargo Book >> Build Scripts
use build_my_react_js::*;

fn main() {
    build_react_under!("my-frontend");
}

Provided the system is configured with NPM, and the repositories are reachable, then it will attempt to compile your React project when changes are detected (and only when changes are detected)

Provided your crate is structured with an additional, uniquely-named subdirectory containing your package.json this can be instructed to enter and build it. Feedback is provided through the Cargo IPC mechanism as build warnings. Panics are fatal to builds, when the commands report failure, but options are available, see the docs.

I’m not sure how “clean” works in the npm ecosystem, but this crate assumes you start potentially without node_modules, and attempts npm install when the project is not built yet.

This could become flaky, but:

  • attempts to preserve quality feedback,
  • rely on quality sources of information,
  • deliver quality feedback,
  • benefit from pipelined builds to speed development,
  • benefit from the full power of the cargo ecosystem

Enjoy!

Macros§

Functions§