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

feat: support package exports and custom paths #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KaelWD
Copy link

@KaelWD KaelWD commented Aug 14, 2022

Frontend PR: pastelsky/bundlephobia#679

Supports the following formats:

bundlephobia
bundlephobia@latest
bundlephobia@latest/dist/index.js
@pastelsky/bundlephobia
@pastelsky/bundlephobia@latest
@pastelsky/bundlephobia@latest/dist/index.js

@@ -28,7 +28,7 @@ server({ port: PORT }, [
})
}
}),
get('/export-sizes', async ctx => {
get('/exports-sizes', async ctx => {
Copy link
Author

Choose a reason for hiding this comment

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

Not sure what's going on here, this is the path the frontend is using.

Copy link
Owner

Choose a reason for hiding this comment

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

This is only a dev server — the frontend uses its own routes and server. But makes sense to synchronize here.

Comment on lines +103 to +112
const mainSizes = mainAssets.reduce((acc, asset) => {
acc.size += asset.size
acc.gzip += asset.gzip
if (asset.parse) {
acc.parse = acc.parse || {baseParseTime: 0, scriptParseTime: 0}
acc.parse.baseParseTime += asset.parse.baseParseTime || 0
acc.parse.scriptParseTime += asset.parse.scriptParseTime || 0
}
return acc
}, { size: 0, gzip: 0, parse: null as null | { baseParseTime: number, scriptParseTime: number } })
Copy link
Author

Choose a reason for hiding this comment

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

I maintain a component library (Vuetify) that imports its own stylesheets. The way this was before would only include the size of the CSS instead of CSS + JS.

console.log(${options.customImports.join(', ')})
`
} else {
importStatement = `const p = require('${packageName}'); console.log(p)`
importStatement = `const p = await import(/* webpackMode: 'eager' */'${importPath}'); console.log(p)`
Copy link
Author

Choose a reason for hiding this comment

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

.mjs can't be .require()d

options,
}: BuildPackageArgs) {
const buildStartTime = performance.now()
let buildIteration = 1

importPath = await resolve(installPath, importPath)
Copy link
Author

@KaelWD KaelWD Aug 14, 2022

Choose a reason for hiding this comment

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

We're still using webpack 4, but have webpack 5's enhanced-resolve. This resolves imports to an absolute path so webpack 4 can load them.

@KaelWD KaelWD marked this pull request as ready for review August 14, 2022 15:36
@pastelsky
Copy link
Owner

Thanks for taking time out to contribute. Support for alternate entry points to a package that was definitely on my radar.
Adding support for this does add entropy to the system though, and make our caching less effective. We should only support the building of specific entry points that are specified in the exports field of a package.

@KaelWD
Copy link
Author

KaelWD commented Aug 21, 2022

That's fair enough, I don't really know how all the caching and historical stats works.
I was thinking about ways we could display other entry points on the main package page, for example https://bundlephobia.com/package/[email protected] doesn't really do much on its own, most of the actual package is under vuetify/components, vuetify/directives, and vuetify/styles. "Only specific entry points" is tricky though because you can have wildcard exports like "./components/*": "./lib/components/*/index.mjs" or "./*": "./*" that allow you to import any file. We also can't really include exports sizes in the main package size because some packages have non-frontend exports like vue/server-renderer.

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.

None yet

2 participants