microbundle icon indicating copy to clipboard operation
microbundle copied to clipboard

Add support to generate package.json during build?

Open FezVrasta opened this issue 5 years ago • 6 comments

Lerna recently added support for the --contents argument.

Basically, it makes it possible to tell Lerna to publish to npm just the content of the dist folder (used as root directory rather than subfolder).

This means that if you have:

dist/
  index.es.js
  index.umd.js
src/
  index.es.js
  index.umd.js
package.json

it will push to npm just the content of dist and you'll be able to import stuff form the package with import umd from 'pkgname/index.umd.js'

The only missing piece is a way to generate a compatible package.json file that must be put inside the dist folder during the build process.

That means that the main (and other) field should be changed from dist/index.js to index.js.

Do you think this is something that Rollup could handle? If so I'd like to work on a PR to add it.

FezVrasta avatar Jan 03 '19 16:01 FezVrasta

Whats the exact use case? If u are ready to write „pkg-name/index.umd.js” i dont see much value in shortening it to that from „pkg-name/dist/index.umd.js”. Those are just 5 characters which u can always alias within ur build setup if u dont like them

Andarist avatar Jan 03 '19 16:01 Andarist

Yeah the example is pretty poor, the real use case is for something like:

dist/
  Button/
  Dropdown/
  Input/
  Whatever/

and you want to do import Button from 'pkg/Button'.

Now that I think about it, that would first need the multi input/output support built into microbundle

FezVrasta avatar Jan 03 '19 17:01 FezVrasta

Now that I think about it, that would first need the multi input/output support built into microbundle

Yeah, I'm planning to work on this one. Gonna start working on various things I'd like to do soon and hopefully we can reach a point when we can work on this one (atm it's somewhat further on my roadmap, but it's there)

Andarist avatar Jan 04 '19 08:01 Andarist

Note that the node resolution algorithm supports nested package.json files. @andrewiggins digged deep into this just a few days ago.

Basically as a workaround you could use that to sort of "fake" multi-entry support in microbundle. Each subfolder would need to have its own package.json file with private: true to prevent accidentally publishing it on npm.

It's obviously not as nice as having true support for multiple entries though...

marvinhagemeister avatar Jan 04 '19 10:01 marvinhagemeister

If you are curious, let me know! Happy to talk more about the multiple entries approach I looked at and share an example repo.

andrewiggins avatar Jan 09 '19 07:01 andrewiggins

I think I know the drill - using this technique in redux-saga ( https://github.com/redux-saga/redux-saga/blob/2082087e27c79bd821b417c0460f6cb7822ff1bf/packages/core/effects/package.json ). If you have anything to add beyond that I would appreciate the insights though!

Andarist avatar Jan 10 '19 09:01 Andarist