-
Notifications
You must be signed in to change notification settings - Fork 363
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
Support for multiple "entries" #50
Comments
Indeed - right now I have to run microbundle multiple times in order to handle disparate input-output flows. |
So I was thinking how this thing can be handled, I think there are 2 fundamental ways of providing this feature (I'll talk about them later) At the moment there is a possibility to pass multiple entry points, even with a glob pattern and for each of the entry points Actually we could also support additional targets, but how to do that have to be figured out. What I mean by additional targets? React Native ( Also ideally we could run a single command of Configuration At the moment when configuring multiple entries we can specify both input files and output directory, but it cannot quite work like that - when providing additional/alternative entries we need to reflect entry name in the package's directory structure. So actually we have 2 options for this: Convention We could support special My choice would be... A mix of configuration and convention approaches - I wouldn't ignore output option ever and create "proxy" directories based on the convention (structure of the source directory). That way all of the created files would be in a single directory (clarity) and we would have a nice way of specifying additional entries (opt-in when options gets used) with automatic creation of "proxy" directories. Additional notes Additional "main" entries - react-native, browser Similar thing could be done for browsers, but we would have to "invent" (?) |
I think I'd prefer to have Microbundle generate directories with derived |
Could you elaborate on this? There is no parity at the moment (w are flat bundling) between src and dist. I think convention files are more error-prone, so I'd suggest configuration is a better choice for this. Anyhow - I've started working on this slowly, hopefully I'll present a PR soon-ish, so we can discuss used approach then. |
Ah but there is, just it's only for multiple entries: their names and locations are mirrored in |
Would be great to add a test for this to see whats the expected result. By quickly inspecting |
OK, i think I've found example use of what you were talking about (which is
Need to look later how unistore/stockroom are different (maybe they just do not refer to each other? i suspect now that they do not refer to their "entries" directly, but probably just to some other imported internal modules and thats why other modules get duplicated - which also doesnt seem ok) or if Ive missed something when inspecting them. I'm not sure yet, because I haven't experimented with this freshness in rollup yet, that ultimately we should use code-splitting (which is available already). This would simplify the microbundle's code, make those things more automatic and we could end up with no duplication between outputted files. |
Seriously, i still can't understand for what you are talking about 😆 Rollup support multiple entry points anyway, even without the code splitting and etc, just pass array to |
Regarding
I think what you mean is that multiple configuration can be passed to rollup in array form, i.e. export default [cjsConfig, esConfig, umdConfig] Those configs would be completely separate though and we'd ideally would like to end up with 0 repetition between output bundles. |
Oh yea yea, I was sleepy 😪 Yup, finally got it. And recently i backed to the @rolldown, so i quickly implemented it in few lines, of course plus bonus features as it was dreamt. Support rich config files, multiple entry points and basic placeholders. Creates the following bundles
|
Is this feature still being worked on? Keen to see it implemented! |
I find it confusing that's cited as a feature in the Line 17 in 1ac4ccc
|
Same @leonardodino Is there already a way to support multiple entry modules? Or is the README wrong? If there is already a way to support multiple non-disparate entry modules, it should probably be documented otherwise it's just confusing to say it exists but not say how to use it |
I'm trying to do the same thing, I want to create a single package for a collection of React components but make it possible for users to access sub components without having to import everything else. Struggling to find a way to do this at the moment. |
@gregrafferty No need for separate bundles. Just use named exports and all popular bundlers will take care of the rest via tree-shaking. |
Ah that's great, thanks for the info. I've had a few problems with this in the past so sometimes I get a bit paranoid about it! |
FYI: We're going to support package exports. |
Being able to specify multiple input > output files, would be most welcome. I'm using microbundle to bundle my serverless functions. I currently have 1 npm script per function, and need to maintain a mapping when adding / removing functions. A glob pattern, or even just multiple entries that map to a output file in a folder, would be of big help. |
I'm trying to conditionally include logic or dependencies based on platform (node.js vs web), with Microbundle. My package supports both platforms but needs extra dependencies in Node.js. The article How to write a JavaScript package for both Node and the browser suggests doing this with the |
@donmccurdy Why do you think exports might not help? Have you read https://nodejs.org/api/packages.html#packages_conditions_definitions and https://nodejs.org/api/packages.html#packages_conditional_exports? There it is explained that a |
I'm not sure what to make of a "browser" exports key being endorsed by Node.js — it's the bundlers for web that I need to support that field. 🙂 There's also a root |
@donmccurdy Ah! For multiple sources I believe you have to run microbundle multiple times. The same way you have to run it multiples times if you want to export multiple subpaths. See for instance how |
This is my most wanted feature 😄 |
Hey, what's the status of this feature? Or even, what's the right way to do this at the moment? Is it multiple package.json? Multiple CLI runs? With which package fields? |
Hmmmm, this seems to work already or am I missing something? microbundle src/{a,b}.js |
But can they have different outputs? Example: i have entry |
I stopped having this use case, but yes, as I remember that worked using the {
"name": "foo",
"exports": {
".": "./dist/foo.modern.js", // import "foo" (the default)
"./lite": "./dist/lite.modern.js", // import "foo/lite"
"./full": "./dist/full.modern.js" // import "foo/full"
},
"scripts": {
"build": "microbundle src/*.js" // build foo.js, lite.js and full.js
}
} with {
"name": "foo",
"exports": {
".": "./dist/foo.modern.js",
"./a": "./dist/a.modern.js",
"./b": "./dist/b.modern.js"
},
"scripts": {
"build": "microbundle src/{a,b}.js"
}
} but I am not 100% sure, sorry Keep in mind that this makes microbundle generate all that, it does not mean that you are restricted to accessing the generated files through monder exports fields. You can additionally add a |
Tried here and didn't worked. I did with an script file. If anyone in the future wants: #!/usr/bin/env bash
echo Starting build...
packages=(
a
b
)
rm -rf ${packages[@]}
echo Target cleared...
for package in "${packages[@]}"; do
yarn microbundle -i src/$package.ts -o $package/index.js --tsconfig 'tsconfig.build.json' --name ${package^} &
done
wait
echo Build complete! And in my package.json {
"scripts": {
"build": "bash build.sh"
},
"exports": {
"./b": {
"import": "./b/index.esm.js",
"node": "./b/index.js",
"require": "./b/index.js",
"default": "./b/index.modern.js"
},
"./a": {
"import": "./a/index.esm.js",
"node": "./a/index.js",
"require": "./a/index.js",
"default": "./a/index.modern.js"
}
}
} EDIT: Added |
@arthurfiorette Just a heads up: having
|
Thanks @arthurfiorette . In addition to your code, I had to use this as my project was using an older version of typescript https://stackoverflow.com/a/69791012/9406951.
And for those looking to export a default module, use the
|
Having this implemented would resolve this issue.
The idea is that we need to output private
package.json
files to support appropriate es/cjs resolving, I believe that @kentcdodds got it "right" here. Although you might prefer having some convention for creating additional "entries" over additional config flag.I will work on implementing this, hopefully some time soon~
The text was updated successfully, but these errors were encountered: