parcel-bundler / parcel

The zero configuration build tool for the web. πŸ“¦πŸš€
https://parceljs.org
MIT License
43.5k stars 2.27k forks source link

PEBCAK or false advertising? #1524

Closed BenSapiens closed 6 years ago

BenSapiens commented 6 years ago

πŸ› bug report

So maybe I'm just retarded, but your bundler isn't actually deduplicating included assets.

πŸŽ› Configuration (.babelrc, package.json, cli command)

Steps to reproduce:

  1. Make two HTML files and two Javascript files.
  2. Link the two Javascript files in the HTML files.
  3. import TweenMax from "gsap"; in both Javascript files. (or react, or any other)
  4. Build.

πŸ€” Expected Behavior

As stated here, "If an asset is required in more than one bundle, it is hoisted up to the nearest common ancestor in the bundle tree so it is not included more than once."

One of the resulting Javascript files should contain the TweenMax library and one shouldn't... right?

😯 Current Behavior

As it is, each imported library is built into each Javascript file. It will be downloaded again and again and again... every time anyone goes to a new page.

πŸ’ Possible Solution

...I don't know, man.

πŸ”¦ Context

I'm just trying to use the spiffiest new build tool around.

πŸ’» Code Sample

dist.tar.gz src.tar.gz

🌍 Your Environment

Software Version(s)
Parcel latest
Node latest
npm/Yarn latest
Operating System MacOS 10.13.4
KeineLimonade commented 6 years ago

Just create a third file where you import both js files and import that one into your HTML with a script tag. That should produce the desired result

devongovett commented 6 years ago

in your scenario, the duplicated JS module does not have a common JS ancestor since it comes from two different HTML entries. therefore, we cannot hoist it up and dedup it. I believe this is working as designed.

BenSapiens commented 6 years ago

Thanks for the reply. I think the problems I'm having with Parcel are my own fault. It seems to rely on a large number of implicit assumptions of which I have no direct knowledge. I'll spend a lot more time trying to figure them out. Great work overall.