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

Can Browserify be used on server-side Node.js? #1540

Closed
techpines opened this issue Apr 8, 2016 · 9 comments
Closed

Can Browserify be used on server-side Node.js? #1540

techpines opened this issue Apr 8, 2016 · 9 comments

Comments

@techpines
Copy link

Can Browserify be used on server-side Node.js?

The Node.js modules system is great, but it leads to some bloat on the filesystem. In most cases, this filesystem bloat isn't really an issue. However, our team has been exploring AWS Lambda, and I'm sure there are similar server-style environments where a smaller code footprint would be helpful. Which is why I thought of Browserify, since it pulls only the dependencies it needs.

Is it possible and if it is, does anyone know if there is any extra configuration needed to make it work properly in a server-style environment?

@joshwnj
Copy link

joshwnj commented Apr 9, 2016

@techpines there's this, which I haven't tried yet but have been meaning to take a look: https://www.npmjs.com/package/noderify

@mderijcke
Copy link

There is a --node flag which does just this.

  --bare

    Alias for both --no-builtins, --no-commondir, and sets --insert-global-vars
    to just "__filename,__dirname". This is handy if you want to run bundles in
    node.

  --no-browser-field, --no-bf

    Turn off package.json browser field resolution. This is also handy if you
    need to run a bundle in node.

  --node

    Alias for --bare and --no-browser-field.

@Cyber1000
Copy link

@techpines: With which solution did you came up? Did noderify work for you?
@mderijcke: Can I use this within gulp? I did something like: browserify({basedir: config.server.path, node: true})�", but can't see a difference, documentation doesn't state that node option in api exists (just on commandline).

@mderijcke
Copy link

Hi @Cyber1000,

It's a bit counter intuitive but if you're using the API (which you are, when using Gulp) you should specify bare: true and browserField: false which is what --node does internally.

So the reason nothing happened is because opts.bare is not actually checked anywhere in the code :-)

@techpines
Copy link
Author

@Cyber1000 I haven't implemented this yet on my end, but I was going to stick with browserify since it's a more mature library and it looks to already has this functionality builtin (plus we're already using it for client-side js)

@Cyber1000
Copy link

Thanks for your answers, in the end I also stick to browserify, I just did an additional "bundleExternal: false" as some third-party-component made problems. So far I got my uglified/browserified server.js up and running.

@rawbin-
Copy link

rawbin- commented Apr 28, 2016

browserify process the Node Global __dirname,How can I make it to be ignored by browserify?

@keksipurkki
Copy link

I was facing this problem, too. I was trying to bundle a bunch of server-side JavaScript and I could not do it with the browserify NodeJS API. Guess the browserify library is not really the right tool for the job anyway as the name suggests.

Turns out you can use webpack (https://webpack.github.io/) and bundle JavaScript by setting 'node' as the target: http://jlongster.com/Backend-Apps-with-Webpack--Part-I .Works like a charm.

@heri16
Copy link

heri16 commented May 20, 2018

@goto-bus-stop Is what is said by @keksipurkki true? I would think Browserify supports node as a target considering this exists https://www.npmjs.com/package/serverless-plugin-browserifier

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

No branches or pull requests

7 participants