ljharb / qs

A querystring parser with nesting support
BSD 3-Clause "New" or "Revised" License
8.47k stars 730 forks source link

ESM & CJS - Built #461

Closed tada5hi closed 1 year ago

tada5hi commented 1 year ago

@ljharb if you are fine with it, i would create a pull request, to support different bundles for cjs and esm with rollup ( + terser for minification ? )

ljharb commented 1 year ago

Why? Packages shouldn't ever bundle, only apps should - and CJS already works with ESM, and with a non-broken node module bundler. What's needed?

tada5hi commented 1 year ago

Why? Packages shouldn't ever bundle, only apps should - and CJS already works with ESM, and with a non-broken node module bundler. What's needed?

You got a point there, but I would just use rollup for its build /transformation pipeline instead of bundling any dependencies in the output. CJS modules only work in server side (node) applications but not in the browser e.g.

ljharb commented 1 year ago

CJS modules work perfectly fine in the browser via a bundler. Nobody should be deploying any JS to a browser except via a bundler.

Rollup makes a bunch of assumptions about which code it can delete that have historically caused lots of bugs, so I wouldn't ever use rollup.

tada5hi commented 1 year ago

CJS modules work perfectly fine in the browser via a bundler. Nobody should be deploying any JS to a browser except via a bundler.

You are completely right, I just thought it would be great, if the end user can directly use this library without using a bundler.

Rollup makes a bunch of assumptions about which code it can delete that have historically caused lots of bugs, so I wouldn't ever use rollup.

Really ? I was not aware of that and had not any problems with it yet. What bundler do you recommend ? What do you think about esbuild and turobopack ?

ljharb commented 1 year ago

For packages, never any bundler - for apps, browserify or webpack 4 (not 5, since it’s broken by design).

tada5hi commented 1 year ago

Thank you for your assessment :blush:. What do you recommend when you write code in TypeScript? In that case you don't get around using something like tsc, esbuild or babel to transpile your code to JS.

ljharb commented 1 year ago

Yes, you would use tsc, or preferably babel, to transpile your code (not bundle it) prepublish.

tada5hi commented 1 year ago

@ljharb isn't qs also affected by this ? https://antfu.me/posts/publish-esm-and-cjs#tsup

ljharb commented 1 year ago

@tada5hi im not sure what you mean “affected” - certainly qs could publish a dual package, but there’d be zero benefit in doing so since CJS is the universal format.

Farnsi commented 1 hour ago

cjs is universal, what is esm? Everything move to esm, it has a reason.

Can't use qs in vite (other one opened the same issue, it is closed, so i not open a new one).