question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Large bundle size with webpack

See original GitHub issue

Actual Behavior

I’m making a Chrome recorder extension, and I’ve noticed the production library bundle was 437KB in my project, which I would consider to be relatively large for a bundle that doesn’t need to ship GUI assets. I’m guessing this is due to a combination of Node.js dependencies and Puppeteer not being originally designed for browser usage (since the DOM and Selenium APIs already support browser automation). This issue may also apply to Puppeteer’s build, but I wanted to open it here because it’s related to the recorder use case.

Steps to Reproduce the Problem

  1. Clone https://gist.github.com/ad7d2641f9b7b8c6012d031edab790c4
  2. npm install
  3. Note the sizes outputted by webpack or on disk

Specifications

  • Version: 0.6.1
  • Platform: macOS

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
OrKoNcommented, Aug 18, 2022

Hey @nickmccurdy I suspect that you don’t require Puppeteer for the extension as we currently only support export extensions? In that case, you can safely exclude Puppeteer (which is an optional peer dependency needed for the replay part) from the bundle. Please see this rollup config https://github.com/cypress-io/cypress-chrome-recorder-extension/blob/main/rollup.config.js#L10 as an example in rollup. I believe a similar configuration should be possible for Webpack. Would that work for your extension?

0reactions
nickmccurdycommented, Aug 22, 2022

Sorry, got distracted working on other things for the extension.

Adding "sideEffects": false to node_modules/@puppeteer/replay/package.json seems to work, as it results in the main.js bundle being empty. This is closer to what we want, because we told webpack it has no side effects and we aren’t using any imports from it. However, this unfortunately still requires installing puppeteer and getting webpack to build it with the fairly large resolve.fallback config.

Does anyone have ideas on how to tree shake away Puppeteer without having to install or configure it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Reduce Your Webpack Bundle Size for Web App ...
So I'm gonna try to give you some tips used by teams working on large apps to reduce the size of their main...
Read more >
Webpack final bundle size is too big - node.js - Stack Overflow
I know I am missing something here. Should be somewhere near to or more than webpack recommendations but 1010 KB is too much....
Read more >
3 ways to reduce webpack bundle size - Jakob Lind
3 ways to reduce webpack bundle size · Easy: Run webpack in production mode · Medium: use an analyzer tool such as webpack-bundle-analyzer...
Read more >
5 Methods to Reduce JavaScript Bundle Size - Bits and Pieces
5 Methods to Reduce JavaScript Bundle Size · 1. Code Splitting with Webpack · 2. Using Webpack Plugins for Tree Shaking · 3....
Read more >
Minimizing Webpack bundle size - Anvil
Learn how to minimize your Webpack bundle size by following these best practices, ensuring an optimal user experience.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found