Parcel: [Question] Is parcel suitable for building a npm package?

Created on 6 Jan 2018  路  10Comments  路  Source: parcel-bundler/parcel

Choose one: is this a 馃悰 bug report or 馃檵 feature request?

A question.

馃帥 Configuration (.babelrc, package.json, cli command)


I'm writing a npm package, where I use the npm script to bundle the src files together into a single file. But I found the dist file doesn't bundle everything together, which causes this error:

/Users/changyan/Documents/repos/test/node_modules/react-animation-wrapper/lib/index.js:12:29: Cannot resolve dependency './emptyFunction'...

and when looking into the bundled file I noticed it's requiring something like this:

var e,r=require("./emptyFunction")

My npm script looks like this:

{
  "build": "parcel build ./src/index.js --out-dir ./lib",
}

And I searched around on the internet but didn't find something useful to resolve my problem. Also, I read a post that addressed that rollup or webpack are probably better choices for writing npm packages. Is that true? Or am I using it wrong?

馃 Expected Behavior

馃槸 Current Behavior

馃拋 Possible Solution

馃敠 Context

馃捇 Code Sample

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel |
| Node |
| npm/Yarn |
| Operating System |

Most helpful comment

All 10 comments

Thanks @jamesmcallister , didn't know about this one!

related to #192 Seems like u found a solution with microbundle ;)

Having the same issue, what's wrong with using parcel-bundler for npm package bundling?

@eldyvoon it should be possible, just not 3 months ago

Sent with GitHawk

@DeMoorJasper or anyone else, so what I'm reading is that adding:

{
  "build": "parcel build ./src/index.js --out-dir ./lib",
}

to one's package.json would remove the need for would remove the need for rollup or microbundle

@djstein it looks parcel build --target node was added in #652.

For libraries Microbundle is intended for building multiple outputs from the same input. In theory you get CJS, ESM, UMD, .min.js, .d.ts, etc. in one pass.

I don't think that's in scope for Parcel?

Interesting... but what about the TS typings files?

Looks like this might be in scope for Parcel 2?

@chocolateboy don't think so.

And still. Rollup HAS problems bundling everything and might be slow. Webpack is the only alternative, but cannot output ESM. There is @purtuga/esm-webpack-plugin, but it is a hack workaround just to make consuming easier. When third party is going to bundle to the generated package, the tree shaking won't work.

So. Yes we need more competition.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

will-stone picture will-stone  路  3Comments

Niggler picture Niggler  路  3Comments

davidnagli picture davidnagli  路  3Comments

algebraic-brain picture algebraic-brain  路  3Comments

devongovett picture devongovett  路  3Comments