Skip to content
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

Bundling Issues with Vite #18

Open
pcfreak30 opened this issue Jul 11, 2023 · 6 comments
Open

Bundling Issues with Vite #18

pcfreak30 opened this issue Jul 11, 2023 · 6 comments

Comments

@pcfreak30
Copy link

I seem to be getting issues with bundling in vite. The target is a webworker in CJS output.

function t(n2) {
  if ("number" == typeof n2 && (n2 = BigInt(n2)), 1n === n2)
    return 1;
  let t2 = 1;
  do {
    t2++;
  } while ((n2 >>= 1n) > 1n);
  return t2;
}

Issue is similar to #16.

I have so far fixed it by forking the repo and bigint-mod-arith and refactoring the build process to just output esm JS and not try to pre-bundle, so it can be processed normally.

I would appreciate seeing that as I never really liked large minified js blobs in NPM packages.

Kudos.

@juanelas
Copy link
Owner

juanelas commented Sep 1, 2023

I'm not sure I understand your issue. ESM (browser and node.js) and CJS (just node.js) are distributed already bundled in the dist directory. Just use the one you need. Why do you need to rebuild?

@pcfreak30
Copy link
Author

I don't remember the details on that, but I do know that I target CJS, so im not sure ESM would make sense.

But the bigger issue is I don't like pre-bundled assets in node packages and you should be leaving it to the end developer to do that. That as a whole is my issue, as I cannot say if ESM would even help.

Your package is in a minority that does it which is causing problems.

Kudos.

@juanelas
Copy link
Owner

juanelas commented Sep 1, 2023

I certainly don't understand what you mean. I build the files and the package.json exports what is needed. You just need to install from npm.js and import/require the package, then the right one is used when you bundle your application. If the problem is that vite is not requiring/importing the right one, it may be an incompatibility with vite's bundler that I may analyse. Is it the case?

@pcfreak30
Copy link
Author

I build the files and the package.json exports what is needed.

Thats the problem. The files should not be pre-bundled to ./dist/index.node.cjs or ./dist/index.browser.esm.js.

@juanelas
Copy link
Owner

juanelas commented Sep 5, 2023

But you shouldn't build my library, you just need what is in the dist (distributable) directory. I have a complex build system to produce the distributables using the same source code. The original typescript sources along with a sourcemap file are provided just in case you need to debug and your debugger understands sourcemap files.

@pcfreak30
Copy link
Author

Your missing the point. I don't want the library using a bundler at all and your in the minority of projects doing it. I would not need to fork if it was just plain js files and no post-processing. The pre-optimization you are doing IS the problem, it is breaking things because a bundler is trying to bundle pre-bundled code.

That solution should not be fix the bundler but offer the un-bundled files in dist, either under main or as an export map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants