Calling npm before build from Cargo


Which is the better/idiomatic way to call npm before building a Rust application?

I have tried using the approach, but it is not called every time, but just only when something changes in my Rust code (instead when my web app code changes), furthermore it is not showing the npm output clearly (using -vv is making it showing lot of information that are hiding more interesting ones).

I am looking for something that it is always called at the beginning of each build and stops the build in case of any issues showing errors. I would like to avoid bash/Python script (for portability or introduction of extra dependencies).

Thank you.

You need to tell cargo that your npm invocation, and thus your execution, depend on non-Rust files, by emitting special rerun-if-changed=path/to/webapp/file commands inside your script; see the documentation.

1 Like

Thank you!

Just another question, there is a way to force to show (on the stdout) the output?

To show build script output, run: cargo build -vv

Yes, I know, but as I was saying in my original post this option is making cargo shows lot of information that are hiding the more interesting ones. :slightly_frowning_face:

Anyway, it is more a cosmetic thing, so it is not a big problem. :blush:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.