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

Node bundling #131

Open
mrvicadai opened this issue Sep 14, 2018 · 6 comments
Open

Node bundling #131

mrvicadai opened this issue Sep 14, 2018 · 6 comments

Comments

@mrvicadai
Copy link

Other bundlers (like webpack) can target node environment instead of browser. That largely involves leaving things like require('fs') and process intact in the code.

Is there a way to do the same in fastpack?
If no, is it on the roadmap?

The use case is when writing a Node application using ReasonML, but don't want to bring the compiler with it when deploying, therefore need to bundle the js code.

@zindel
Copy link
Member

zindel commented Sep 18, 2018

Hi, @mrvicadai. Thanks for the request! Unfortunately, it is impossible in the fastpack at the moment. We've been targeting browsers first. There are some builtin (not pluggable) features which prevent an easy addition of the node target at the moment:

  1. Fastpack considers the browser field.
  2. Requiring fs, path and other builtin Node.js packages leads to an error with the suggestion of the browser-friendly mocks
  3. process.env.NODE_ENV is replaced across the codebase with the constant (development or production) as well as non-matched if/ternary branches are pruned.

If I understand the feature request correctly, for the node target you definitely don't want (1). (2) should leave require statements intact. What about (3)? Is it desired behaviour or it should be skipped as well? Is there anything else specific about the node target?

@juancampa
Copy link

I'm also interested in targeting node. Another difference that comes to mind is window vs global as the global object. Not sure if that's builtin or not

@mrvicadai
Copy link
Author

Hi @zindel thanks for the reply! I think you're correct that (1) and (2) are preventing node environment from working. Not necessarily (3) though since the application might need different configuration profiles depending on the environment.

@juancampa also made a good point that global is the "Pervasive" variable in Node, as well as __dirname and __filename as seen here.

@zindel
Copy link
Member

zindel commented Sep 21, 2018

@juancampa @mrvicadai could you suggest a reasonably simple (but still with some dependencies) app we could use for testing?

@mrvicadai
Copy link
Author

mrvicadai commented Sep 22, 2018

@zindel I was looking at the source tree of the parcel bundler and found some integration test cases that might just serve as SSCCE for this:

In terms of real world example, I can think of this one as reasonably small, but very frequently used node package: https://github.com/isaacs/rimraf/blob/master/rimraf.js

@MoOx
Copy link

MoOx commented Jan 30, 2019

Also what could be interesting for (2) is that we have a way to ignore some require() to be considered. See https://arunoda.me/blog/ssr-and-server-only-modules for an example. Webpack have its IgnorePlugin for this purpose.

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

4 participants