GithubHelp home page GithubHelp logo

browserify-tests's Introduction

Browserify tests

What is Browserify?

When I first came across Browserify, I thought it would be a client-side script to add support for CommonJS modules. I thought it would add some sort of global module variable and define a require function and work the exact same as RequireJS, except for not being asynchronous.

I was wrong. Browserify works on the server-side. It's an NPM package. Here's a quick description taken from handbook:

Browserify starts at the entry point files that you give it and searches for any require() calls it finds using static analysis of the source code's abstract syntax tree.

Browserify is a compiling tool. Every require() and module.exports call will be removed and Browserify will generate a bundle file that will automatically contain every dependencies in the correct order.

Installing Browserify and the sample project

In order to install Browserify, run this CLI:

$ npm install -g browserify

Now clone Browserify-tests

$ git clone https://github.com/andrerpena/browserify-tests.git

Sample project

The sample project contains 3 modules, in the lib directory. Every module should create some sort of object and then assigning module.exports to that object. Whatever is passed to module.exports represents the module itself. In the sample project, there are 2 modules, logger.js and emailSender.js, and logger.js depends on emailSender.js.

When compiling a Browserify bundle, you can choose one ore more entry points. In our case, the entry point is main.js. Browserify is supposed to detect that main.js depends on logger.js and that the later, in turn, depends on emailSender.js. Browserify should, then, generate the output bundle.

In order to generate the bundle:

$ browserify ./lib/main.js > bundle.js

This should do it. The > bundle.js instruction tells Broserify to output the bundle to the given file. If this parameter is not provided, Browserify will just output the bundle to stdout.

To verify that the bundle works correctly:

$ node bundle.js

And that should output:

this is working fine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.