A Simple Way to Use NPM Library in Browser

Occasionally, we need to use a JS library in our browser side, yet it’s only available from the NPM repository.

As usual, the Google result of any NPM related questions will bring you more yes-and-no answers, and leave you in further confusions and headaches.

Well, life better be simpler 🙂

Say, we are going to use the NPM library of email-js-mime-parser and buffer in the browser, all we need to do is:

  1. install browserify tool

npm install -g browserify

  1. install npm libraries

npm install emailjs-mime-parser
npm install buffer

  1. create a new JS file, main.js

  1. compile the main.js:

browserify main.js -o bundle.js

  1. use bundle.js in normal webpage, and you could use parseEmail and Buffer in the browser side JS:

(Note that default is needed for emailjs-mime-parser because of legacy export syntax.)

And that’s all

A Small Git Problem
(And why I am still uncomfortable with Git)

Recently, I have used Trac to manage a git project, and I used a git post-receive hook to sync the commit back to Trac.

The hook starts with something like this:

It works fine for most cases, however, when I try to push a new branch to remote, the $oldrev becomes 0, and caused problem.

fatal: ambiguous argument '0..70e0844': unknown revision or path not in the working tree.

Read more A Small Git Problem
(And why I am still uncomfortable with Git)