Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Should mark package.json dependencies as external by default #42

Open
mesqueeb opened this issue Jan 18, 2020 · 8 comments
Open

Should mark package.json dependencies as external by default #42

mesqueeb opened this issue Jan 18, 2020 · 8 comments

Comments

@mesqueeb
Copy link
Contributor

mesqueeb commented Jan 18, 2020

I'm just thinking that for the es and cjs builds, it should mark all package.json dependencies as external by default:

const pkg = require('../package.json')
const external = Object.keys(pkg.dependencies || [])

Not doing so will include all dependencies as part of the resulting built files. This gives webpack of developers who import your package a harder time eliminating duplicate dependencies.

Please note that passing them as "external" in rollup, they don't need to be added as peer dependency. They will be installed automatically when a dev does npm i or yarn add on your package.

@mesqueeb
Copy link
Contributor Author

Another benefit to doing so is that it becomes clear on bundlephobia what is taking up space:

This is the example before marking dependencies as external:
image

This is the same package after marking dependencies as external:
image

@rstoenescu
Copy link
Member

Of course. Please PR it.

@mesqueeb
Copy link
Contributor Author

@rstoenescu cool thanks! I'll PR asap!!

@hawkeye64
Copy link
Member

Love this idea! Thanks Luca! @mesqueeb

@hawkeye64
Copy link
Member

hawkeye64 commented Jan 21, 2020

I wonder if this would accomplish something similar: rollup-plugin-peer-deps-external - https://www.npmjs.com/package/rollup-plugin-peer-deps-external

@hawkeye64
Copy link
Member

hawkeye64 commented Jan 28, 2020

Ok, I am not so thrilled with this concept any longer. I tried it out on a few projects with bad results. The issue I had was using an external dependency as a mix-in. This caused rollup to not bundle the dep, which would then require the user to have a way to use it with UMD and that mix-in does not have a UMD equivalent.

@mesqueeb
Copy link
Contributor Author

@hawkeye64 the idea is to set all dependencies as external, but only for es and cjs builds as I mentioned.

For UMD build, as you mention, it's better that all dependencies do get bundled with the result. 😉

@hawkeye64
Copy link
Member

Ah, I see. That would be better. Still looking forward to your PR then. :)

mesqueeb added a commit to mesqueeb/quasar-starter-kit-ui that referenced this issue May 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants