Minify the JS code with wasm32-unknown-unknown target
When using the -emscripten targets it automatically runs UgilfyJS on the .js code, but when using wasm32-unknown-unknown it doesn't. This results in extra code bloat.
I propose to have cargo-web automatically run UglifyJS on the .js code when using the target wasm32-unknown-unknown
That is something I've been thinking about, however I'm somewhat reluctant to depend on external non-Rust tools. (Supporting such tools across all three operating systems is a significant headache.)
It would be great if we'd had something like uglify written in pure Rust. (We could then also reuse the JS parsing core to verify that the js! snippets are syntactically correct.)
I understand the concern about external dependencies. In this particular case UglifyJS is cross-platform, since it runs on Node.
As an alternative, if cargo-web can get excellent support for Webpack and/or Parcel then we can rely on those external tools to run UglifyJS.
As someone who wants to integrate the code generated by cargo-web into an existing javascript build system, I'd like to keep the option to not have it minified, because minification makes it impossible to import the file, due to parsing errors (I already went through this with emscripten). My javascript pipeline already does the minification at the end anyways.
@anlumo Minifiers don't change behavior, so you should absolutely not be getting any errors. What minifier did you use?
I‘m using UglifyJS. The program that doesn’t work with minified code is babel.
@anlumo Well, that sounds like a bug in Babel, then! If you want, you can try creating a reduced test case and submitting it to the Babel team, but that's up to you.
In any case, I agree that it should be possible to disable minification (using a flag or Web.toml option).
Yeah, they'd just tell me to run uglifyjs after babel. It's not Rust, the JavaScript community does not believe in rock solid code that can handle anything.