-
Notifications
You must be signed in to change notification settings - Fork 507
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
Better Pre-shaking support (multi-entry) #365
Comments
yea this is clearly a highly requested feature. i'm interested in convention over configuration for this one. once i can require maybe the solve here is |
@sw-yx I'm looking at bundlephobia https://bundlephobia.com/result?p=@react-google-maps/api@1.8.0 at my package built with tsdx, and I see that there is 14.2kb gzipped total, and each export is 14.1kb, so clearly there is no pre-tree-shaking here. before with webpack and babel I could build each component in separate file, and later import each component from it's ./lib/ production file. and so it would take even less code to be added to the final product. |
@sw-yx +1 for convention. As for entries, yeah we could restrict src, test, types, etc. |
I'm not a user of TSDX myself - but I'm kinda into optimizing libraries structure etc and have thought & used different strategies in the past. I think what https://github.com/preconstruct/preconstruct does currently is the sweat spot for multi-entries. There is a config like this: Locations etc cannot be configured - everything works by convention and preconstruct validates values in those nested package.json files etc + offer to fix them if they dont follow the convention. |
Hey, I'm maintaining React-use-gesture and have been using I'm not sure I understand the gist of tree-shaking, but I was wondering if this was related to @jaredpalmer first post? |
@dbismut I've analyzed your bundle and it seems there is nothing wrong with it (at least not in a way that would result in full size to be reported for each individual export). It seems that this is a bug in bundlephobia. |
I guess I’ll check with them directly thanks @Andarist |
might be too restrictive, but why not just look at the files array in pkg.json? Aside from dist, could we presume if any other item in the array has a matching sister .ts or .tsx file in src that we should output a top level .js file? As an mvp, I’m not sure we need to deal with folders even, we can add later. Fundamentally the files array is the source of truth anyways. Thoughts ? |
|
@Andarist what's your suggestion then? |
I think "proxy directories" are the only way to go - with a single config producing a single file output set for given entries. What I mean - if you output That's the easy part, as building such config for rollup is rather trivial. Problem is - how to express intent for multi-entries in tsdx configuration (and if you should output those proxy directories automatically or not). From what I see tsdx is mostly 0-config, but it has some configuration as CLI options? I see it being used for example here: Line 294 in 158ee9a
I would advise creating basic support for config files (maybe just package.json key? although not personally I'm not a fan of configs in package.json), because it really seems easier to work with than a long list of CLI args. With that in place, I would start with adding support for simple case - no globs, nothing fancy, just an exact list of desired output entries. A convention that they have to match exactly to files inside With such a list you could generate those extra directories for a user with appropriate package.json files inside them. I would only be extra careful here - you shouldn't just try to overwrite existing files and if you find existing stuff you should validate their content against expected shape. It shouldn't be an exact match, but rather you should just validate main/module (and other fields if necessary). I wouldn't be concerned with cleaning those directories, let them be committed - it doesn't really matter. Validating a package setting (looking up package.json#files and .npmignore) if they are going to be published with a package would definitely be a nice touch. |
@Andarist would be great if you could take a look at #367 , which supports multiple entries, including globs (which were added, but non-functional, in #175 ), and considers various trade-offs mentioned here.
This is one issue I'm not sure how to handle with Rollup. Rollup has code-splitting, but it creates async split-points, whereas just sharing code between entries could be done with ordinary sync modules/split-points. I think both re-using code between entry bundles and |
Just an update here that I've figured out how to do code-splitting in #367 (which still hasn't been reviewed or merged). And I've added a separate PR for Auto |
Tree shaking is fragile, it would be nice to support preshaking more easily in cjs and esm. Right now, because of how we handle the cjs entry point using the name flag, you would have to run tsdx once for each entry to get Dev / Prod behavior. Maybe this is fine, but maybe there is a cleaner way with tsdx config or cli flags. One idea would be to pass multiple names that are comma separated and then map to each entry file. However in big ui libs, that wouldnot scale well, so maybe we could take a glob pattern?
I also think that we might want to automate the creation of the root level export files. All these .js files do is export the correct dist file. This is required though for require(‘formik/Field’) instead of require(‘formik/dist/Field’). We also may want to update ensure that these root files are correctly list in package.json files array
Thoughts?
The text was updated successfully, but these errors were encountered: