Build stylus-lang from source
eight04 opened this issue · 10 comments
I have successfully bundled stylus/stylus#2394 to a single file. Here is the result:
https://github.com/eight04/stylus-lang-bundle/blob/dev-bundle/dist/stylus-renderer.min.js
Should I create a stylus-lang fork merged with stylus/stylus#2394 and stylus/stylus#2416 under openstyles
?
And I will try to implement the bundle process in this repo.
It's considerably smaller than the official site's library.
Anyway, can't say anything without seeing it actually running in Stylus.
Can you integrate it and link here please?
Looks like a clean drop-in replacement.
Why is it much smaller then?
I didn't investigate how official stylus-lang is built, so I can only tell how I build it:
rollup
can produce smaller bundles with tree shaking/scope hoisting features.- Some file-related/unneeded modules are pruned:
https://github.com/eight04/stylus-lang-bundle/blob/97408c15c2845c31f5647270118c7330964166ba/rollup.config.js#L31-L32 - Some dependencies are shimmed with smaller packages/native modules:
https://github.com/eight04/stylus-lang-bundle/blob/dev-bundle/shim/crypto.js
https://github.com/eight04/stylus-lang-bundle/blob/dev-bundle/shim/events.js
https://github.com/eight04/stylus-lang-bundle/blob/dev-bundle/shim/url.js - Compressed with
terser
, which supports variable name mangling.
I wonder if it's possible to switch to the native SHA-1 via window.crypto.subtle.digest...
Overall, looks good, I think.
@Mottie?
create a stylus-lang fork merged with stylus/stylus#2394 and stylus/stylus#2416 under openstyles
What about this?
AMO will get intensely butthurt about us modifying The Sacred Source of a third-party addon, so it's about whether @Mottie is willing to try to convince them that those are nasty bugs with trivial fixes that should have been applied upstream a long time ago.
Should I create a stylus-lang fork
I'd say overwrite the files in this repo if it's going to be our main resource; it's only hosting the min file, not building anything.
rollup
can produce smaller bundles
Awesome! I'm glad you figured it out. I was having a hard time with rollup.
Overall, looks good, I think.
I haven't looked at the code or tested it, but if it works I'm all for replacing it.
@Mottie is willing to try to convince them...
Not an issue. If it's smaller and better, I'll deal with AMO.
I'd say overwrite the files in this repo if it's going to be our main resource; it's only hosting the min file, not building anything.
I don't fully understand. Do you mean to put build scripts in a new repo? I think we only need 2 repos (including this one):
openstyles/stylus-lang
- A stylus-lang fork with some bugfixes. When upstream (stylus/stylus
) updates, it can be merged directly. This repo doesn't need to be published to npm.openstyles/stylus-lang-bundle
- Bundlesopenstyles/stylus-lang
to a single file. The single dist file generated by the build script could be published to npm.
Sorry, I meant you could overwrite this repo stylus-lang-bundle
with the code from your https://github.com/eight04/stylus-lang-bundle repo. Everything else sounds good.