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

Reduce built library size #277

Merged
merged 6 commits into from
Nov 22, 2024
Merged

Reduce built library size #277

merged 6 commits into from
Nov 22, 2024

Conversation

jamesnw
Copy link
Contributor

@jamesnw jamesnw commented Nov 22, 2024

Description

This reduces the size of the built library from 223.72KiB to 105.54KiB by:

  1. Switching to using more granular imports for csstree.
  2. Removing source-map-js from the built library. Source maps are still generated, but the module itself isn't needed.

Pre-merge cleanup:

  • Remove bundle-stats plugin?

Related Issue(s)

#276

Steps to test/reproduce

  • Verify that the demo works locally, by building, and then changing the import in index.html to import polyfill from '/dist/css-anchor-positioning-fn.js';
  • Locally, run npm run build; open dist/bundle-stats.html to check the results. (You can compare with the current build on the prev-stats branch, which has the bundle-stats plugin installed with no modifications to main.

Show me

Before
image

After
image

Copy link

netlify bot commented Nov 22, 2024

Deploy Preview for anchor-position-wpt canceled.

Name Link
🔨 Latest commit 4501eb3
🔍 Latest deploy log https://app.netlify.com/sites/anchor-position-wpt/deploys/6740b8c152a81500078e618d

Copy link

netlify bot commented Nov 22, 2024

Deploy Preview for anchor-polyfill ready!

Name Link
🔨 Latest commit 4501eb3
🔍 Latest deploy log https://app.netlify.com/sites/anchor-polyfill/deploys/6740b8c117e7a6000829cfc4
😎 Deploy Preview https://deploy-preview-277--anchor-polyfill.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@jamesnw jamesnw linked an issue Nov 22, 2024 that may be closed by this pull request
src/@types/css-tree.d.ts Outdated Show resolved Hide resolved
vite.config.ts Outdated
},
plugins: [bundleStats()],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we have multiple outputs, this is just giving us the stats for the last build, but I don't think there's a benefit for auditing the builds separately.

I'm leaning towards leaving this installed, as it can help us keep an eye on the bundle size.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense. I moved it to devDependencies and made it less verbose, but the generated reports are still there.

@@ -37,7 +38,12 @@ export default defineConfig({
emptyOutDir: !process.env.BUILD_FN,
target: 'es6',
sourcemap: true,
rollupOptions: {
external: [/source-map-js/],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to provide a name in output.globals? There's a warning message emitted-

`No name was provided for external module "source-map-js/lib/source-map-generator.js" in "output.globals". We don't really need to expose it, I don't think?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don't think it really matters. I added it just to silence the warning, since I don't love getting used to "ignore these warnings" if we don't have to.

@jamesnw jamesnw merged commit 7b3586f into main Nov 22, 2024
14 checks passed
@jamesnw jamesnw deleted the size-audit branch November 22, 2024 19:26
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.

Audit polyfill size
2 participants