Questions tagged [browserify]

Browserify is a tool that packages Node.js modules for a web browser.

Browserify is a tool that allows using Node.js modules on a client side.

Browserify combines selected modules into one file that can be added as a script into an HTML page. It adds support for CommonJS-style require and also emulates most of Node standard library. For example, http module is emulated using XMLHttpRequest and buffer module uses TypedArrays.

Browserify Pros:

  1. Ability to reuse the same code on a server (in Node.js applications) and on a client. Many Node modules that don't use IO or talk to file system just work with Browserify.

  2. Support for CommonJS modules. Many developers prefer CommonJS to AMD due to more verbose notation of the latter:

    CommonJS (Node):

    // foo.js
    var bar = require('bar');
    // use bar ...
    module.exports = // some object or function
    

    AMD:

    // foo.js
    define('foo', function (require) {
        var bar = require('bar');
        // use bar ...
        return // some object or function
    });
    
  3. Browserify doesn't prevent developer from using client-side libraried and frameworks like jQuery, YUI, Backbone, etc.

  4. Browserify supports flexible transform options to handle non-javascript file require()s, like CoffeeScript, Handlebars/Jade templates, etc.

Browserify Cons:

  1. Browserify adds a compilation step and thus requires a build process for your client-side code. Most AMD loaders allow writing modules that do not require a compilation at a price of verbocity.

  2. Not all Node of standard library is supported. Notable omissions are support for Streams, File System, TCP and UDP networking, etc.

  3. Native Addon Modules are not supported.

  4. Browserify library for supporting Node API increases the size of resulting code. Some of that overhead can be reduced with code minifiers that supports dead code elimination like Google Closure Compiler or Uglify JS.

2920 questions
141
votes
17 answers

How to import jquery using ES6 syntax?

I'm writing a new app using (JavaScript) ES6 syntax through babel transpiler and the preset-es2015 plugins, as well as semantic-ui for the style. index.js import * as stylesheet from '../assets/styles/app.scss'; import * as jquery2 from…
Édouard Lopez
  • 32,718
  • 23
  • 108
  • 161
120
votes
2 answers

Task Runners (Gulp, Grunt, etc) and Bundlers (Webpack, Browserify). Why use together?

I am a bit new to the task runner and bundler world and while going through things like Grunt, Gulp, Webpack, Browserify , I did not feel that there is much difference between them. In other words, I feel Webpack can do everything that a task…
invincibleDudess
  • 1,682
  • 2
  • 9
  • 17
114
votes
3 answers

How to uglify output with Browserify in Gulp?

I tried to uglify output of Browserify in Gulp, but it doesn't work. gulpfile.js var browserify = require('browserify'); var gulp = require('gulp'); var uglify = require('gulp-uglify'); var source =…
Nik Terentyev
  • 2,150
  • 3
  • 13
  • 22
101
votes
12 answers

Browserify - How to call function bundled in a file generated through browserify in browser

I am new to nodejs and browserify. I started with this link . I have file main.js which contains this code var unique = require('uniq'); var data = [1, 2, 2, 3, 4, 5, 5, 5, 6]; this.LogData =function(){ console.log(unique(data)); }; Now I Install…
SharpCoder
  • 15,708
  • 34
  • 126
  • 225
93
votes
6 answers

How to get minified output with browserify?

Just started to use browserify, but I cannot find documentation for how to get it spilling out minified output. So I am looking something like: $> browserify main.js > bundle.js --minified
Fdr
  • 3,616
  • 5
  • 25
  • 39
87
votes
4 answers

Is it okay to use babel-node in production

I have been developing a site using babel-node and browserify with the babelify transform, to support ES6 syntax. I am just wondering, can I run this in production as babel-node server rather than node server What other options do I have to run ES6…
svnm
  • 17,405
  • 18
  • 82
  • 100
85
votes
9 answers

browserify error /usr/bin/env: node: No such file or directory

I installed node js and npm via apt-get install and all of the dependencies, then I installed browserify npm install browserify -g it goes through the process and it seems like it installed correctly, but when I try to do a simple bundle per this…
Eduardo Dennis
  • 12,511
  • 11
  • 72
  • 102
75
votes
3 answers

Browserify, Babel 6, Gulp - Unexpected token on spread operator

I'm trying to get my Browserify/Babelify/Gulp working in my project, but it won't take the spread operator. I got this error from my gulpfile: [SyntaxError: /Users/mboutin2/Desktop/Todo-tutorial/src/reducers/grocery-list-reducers.js: Unexpected…
Mike Boutin
  • 5,015
  • 11
  • 34
  • 63
74
votes
1 answer

Where should ReactDOM be imported from?

After upgrading to version 0.14.2, I see an error and recommendation to use ReactDOM.render() instead of React.render(), but whence do I import it? When I don't import it and just running as it is, it shows it as undefined. Is it a built-in…
Sergei Basharov
  • 43,294
  • 56
  • 177
  • 295
65
votes
5 answers

How to save a stream into multiple destinations with Gulp.js?

const gulp = require('gulp'); const $ = require('gulp-load-plugins')(); const source = require('vinyl-source-stream'); const browserify = require('browserify'); gulp.task('build', () => browserify('./src/app.js').bundle() …
Konstantin Tarkus
  • 35,208
  • 14
  • 127
  • 117
63
votes
1 answer

What is the difference between browserify/requirejs modules and ES6 modules

I'm still new to ES6 and module loaders and I'm currently looking at combining a browserify setup with ES6. I was wondering if I would still need browserify/requirejs if I'm using ES6 modules. Seems like both allow you to define modules and export…
joerideg
  • 1,748
  • 1
  • 12
  • 18
59
votes
2 answers

Why do I have to use vinyl-source-stream with gulp?

I am trying to use gulp and browserify to transform my .jsx files into .js files. var gulp = require('gulp'); var browserify = require('browserify'); var reactify = require('reactify'); gulp.task('js', function () { …
Sung Cho
  • 5,411
  • 12
  • 39
  • 80
58
votes
10 answers

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' - Gulp

Consider the following two files: app.js import Game from './game/game'; import React from 'react'; import ReactDOM from 'react-dom'; export default (absPath) => { let gameElement = document.getElementById("container"); if…
TheWebs
  • 10,087
  • 21
  • 77
  • 164
56
votes
4 answers

Vue JS 2.0 not rendering anything?

Using Vue (^2.0.0-rc.6) + Browserify, entry point is index.js: import Vue from 'vue' import App from './containers/App.vue' new Vue({ // eslint-disable-line no-new el: '#root', render: (h) => h(App) }) App.vue: