Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First attempt at adopting Parcel #1186

Merged
merged 25 commits into from
Jan 20, 2023
Merged

First attempt at adopting Parcel #1186

merged 25 commits into from
Jan 20, 2023

Conversation

captbaritone
Copy link
Owner

@captbaritone captbaritone commented Sep 28, 2022

Still a number of things to get working:

  • Build UMD build(s)

  • Ensure files are included in npm release

  • Ensure Netlify deploy will work

Optional

  • Split demo site into separate project
  • Custom transform for optimizing skin images

@netlify
Copy link

netlify bot commented Sep 28, 2022

Deploy Preview for vigorous-lalande-5190c2 canceled.

Name Link
🔨 Latest commit c9a8651
🔍 Latest deploy log https://app.netlify.com/sites/vigorous-lalande-5190c2/deploys/63cae026c5124a000858a894

@github-actions
Copy link

github-actions bot commented Sep 29, 2022

Size Change: -459 kB (removed) 🏆

Total Size: 0 B

Filename Size Change
./packages/webamp/built/webamp.bundle.min.js 0 B -276 kB (removed) 🏆
./packages/webamp/built/webamp.lazy-bundle.min.js 0 B -183 kB (removed) 🏆

compressed-size-action

"jest": "^27.5.1",
"prettier": "^2.3.2"
"prettier": "^2.3.2",
"stream-browserify": "^3.0.0"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did all of these changes come from?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is some import to a Node builtin modul (e.g. stream), Parcel autoinstalls the corresponding polyfill.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And same goes for the two Parcel plugins listed in here, which are installed on demand. And in this case, you forgot the bump them when upgrading to "parcel": "^2.8.2")

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh awesome! I assumed it was something like this, thanks for commenting.

BTW, shipping this is currently blocked on some significant size regressions. Webamp lazy is the simpler case to debug since it doesn't pull in some of the heavy dependencies like JSZip.

Using the bundle analyzer reporter gives a nice looking report, but it's dominated by "code from unknown sources". So my next step is to try to figure out what's contributing to this regression.

https://enchanting-khapse-0a90c1.netlify.app/webamp-lazy.html

If you happen to have any tips on how to diagnose, that'd be super helpful!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"isLibrary": true makes the default "optimize": false, because you usually don't want published libraries to be minified. But you can override that of course (I assume you want minification as they're called *.min.js?):

--- packages/webamp/package.json
+++ packages/webamp/package.json
@@ -15,7 +15,8 @@
     "webamp": {
       "source": "js/webamp.js",
       "outputFormat": "esmodule",
-      "isLibrary": true
+      "isLibrary": true,
+      "optimize": true
     },
     "webamp-browser": {
       "source": "js/webampBrowser.js",
@@ -24,7 +25,8 @@
     "webamp-lazy": {
       "source": "js/webampLazy.tsx",
       "outputFormat": "esmodule",
-      "isLibrary": true
+      "isLibrary": true,
+      "optimize": true
     },
     "demo-site": {
       "source": "demo/index.html"
@@ -36,7 +38,7 @@

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. It looks like the remaining difference for the lazy version is entirely attributable to the fact that I haven't yet ported my image optimization to Parcel.

I tried manually checking the optimized version of the CSS into the repo and we are now at ~3% reduction in bundle size!

Reading the Parcel docs it implies that png images are automatically optimized. It looks like that does not apply to png images that exist as data uris in CSS files (that's what my custom Webpack loader does). Is that an optimization that Parcel could/should apply? It seems in keeping with Parcel's approach of automatically applying optimizations where it can, but I also get that this is quite an edge case.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Is that an optimization that Parcel could/should apply? I also get that this is quite an edge case.

Yeah, but it should be possible to support in Parcel.

An alternative here (and this might even be preferable just from a code authoring perspective) is putting these inline PNGs into separate files and then using Parcel's feature to inline it as a data-url: https://parceljs.org/features/bundle-inlining/#inlining-as-a-data-url

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think a "normal" app would work this way, but Webamp has built in support for loading custom "skins", which means it converts the zip file into CSS (with embedded data uris) in the browser. The way I generate the default skin CSS file is I load the custom skin and copy out the generated CSS. This means there's not a reasonable way to get those (probably hundreds) of png files as actual files on the file system.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you saw, I raised the issue on the Parcel repo: parcel-bundler/parcel#8758 (comment)

I'll probably just keep my existing setup unless that feature looks appealing to someone to implement.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see if I can fix that parcel issue you mentioned -- I'll recomment here if I get to it.

@captbaritone captbaritone merged commit 6a71878 into master Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants