trunk-rs / trunk

Build, bundle & ship your Rust WASM application to the web.

Home Page:https://trunkrs.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minification of some javascript is breaking some functionality.

coravacav opened this issue · comments

Running into some issues adding javascript to an app. Without minification, you get
image
Which seems to be a result of minification.

I've created a relatively minimal reproduction here.

Changing

<script data-trunk src="treesitter/tree-sitter.js"></script>

to

<script data-trunk data-no-minify src="treesitter/tree-sitter.js"></script>

during a release build (otherwise modification in general is disabled) solves the problem.

A note from further testing: it seems that with serve, only the javascript of the tree-sitter must not be minified. However, when built, the tree-sitter wasm also needs to be minified. This seems to be a well-known issue for treesitter as seen here tree-sitter/tree-sitter#927, however it still seems notable to bring up here because the change in javascript behavior is still probably not ideal.

I am not sure what the exact problem is. I do recall issues where the JS file was actually a module JS file. That can make a difference. For that you would need to set type="module" (also see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type).

Trunk uses https://github.com/wilsonzlin/minify-js for JS minification (we use 0.5.6, as 0.6.0 also had some issues). So it would make sense to open an issue on that project.

I am not sure if there's something that trunk could do better? If so, please let me know.

Sorry for not replying sooner.

Adding type="module" changes the error to be

highlighting-b62b1cbd3f28dbb8.js:1 Uncaught TypeError: Cannot read properties of undefined (reading 'init')
    at highlighting-b62b1cbd3f28dbb8.js:1:19

I'll also open an issue over there when I find some time, but I am leaving this here for posterity's sake.