cargo-web icon indicating copy to clipboard operation
cargo-web copied to clipboard

Minify the JS code with wasm32-unknown-unknown target

Open Pauan opened this issue 7 years ago • 7 comments

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

Pauan avatar Feb 18 '18 18:02 Pauan

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

koute avatar Feb 19 '18 17:02 koute

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.

Pauan avatar Feb 19 '18 18:02 Pauan

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 avatar Dec 12 '18 03:12 anlumo

@anlumo Minifiers don't change behavior, so you should absolutely not be getting any errors. What minifier did you use?

Pauan avatar Dec 12 '18 13:12 Pauan

I‘m using UglifyJS. The program that doesn’t work with minified code is babel.

anlumo avatar Dec 12 '18 13:12 anlumo

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

Pauan avatar Dec 12 '18 13:12 Pauan

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.

anlumo avatar Dec 12 '18 13:12 anlumo