Skip to content

Commit e9403fd

Browse files
committed
README update for browserify/webpack. add .git and demo to .npmignore
1 parent 2159838 commit e9403fd

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
.git
12
.gitignore
23
bower.json
34
data
45
data-scripts
6+
demo
57
test
68

README.md

+27-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ To pull in updates and bug fixes:
5353
bower update zxcvbn
5454
```
5555

56-
## Node / npm / browserify
56+
## Node / npm
5757

5858
zxcvbn works identically on the server.
5959

@@ -64,8 +64,6 @@ $ node
6464
> zxcvbn('Tr0ub4dour&3');
6565
```
6666

67-
And should automatically work with browserify. The easiest browserify setup is to include zxcvbn in your main bundle. If script size is an issue, see the [performance](#perf) section below for tricks to reduce latency.
68-
6967
## RequireJS
7068

7169
Add [`zxcvbn.js`](https://raw.githubusercontent.com/dropbox/zxcvbn/master/lib/zxcvbn.js) to your project (using bower, npm or direct download) and import as usual:
@@ -76,6 +74,29 @@ requirejs(["relpath/to/zxcvbn"], function (zxcvbn) {
7674
});
7775
```
7876

77+
## Browserify / Webpack
78+
79+
If you're using `npm` and have `require('zxcvbn')` somewhere in your code, browserify and webpack should just work. But we recommend against bundling zxcvbn via tools like browserify and webpack, for three reasons:
80+
81+
* Minified and gzipped, zxcvbn is still several hundred kilobytes. (Significantly grows bundle size.)
82+
* Most sites will only need zxcvbn on a few pages (registration, password reset).
83+
* Most sites won't need `zxcvbn()` immediately upon page load; since `zxcvbn()` is typically called in response to user events like filling in a password, there's ample time to fetch `zxcvbn.js` after initial html/css/js loads and renders.
84+
85+
See the [performance](#perf) section below for tips on loading zxcvbn stand-alone.
86+
87+
Tangentially, if you want to build your own standalone, consider tweaking the browserify pipeline used to generate `dist/zxcvbn.js`:
88+
89+
``` shell
90+
browserify --debug --standalone zxcvbn -t coffeeify --extension='.coffee' -t uglifyify src/main.coffee | exorcist dist/zxcvbn.js.map >| dist/zxcvbn.js
91+
```
92+
93+
* `--debug` adds an inline source map to the bundle. `exorcist` pulls it out into `dist/zxcvbn.js.map`.
94+
* `--standalone zxcvbn` exports a global `zxcvbn` when CommonJS/AMD isn't detected.
95+
* `-t coffeeify --extension='.coffee'` compiles `.coffee` to `.js` before bundling. This is convenient as it allows `.js` modules to import from `.coffee` modules and vice-versa. Instead of this transform, one could also compile everything to `.js` first (`npm run prepublish`) and point `browserify` to `lib` instead of `src`.
96+
* `-t uglifyify` minifies the bundle through UglifyJS, maintaining proper source mapping.
97+
98+
Note that it is not advisable to "rebrowserify" or webpack `dist/zxcvbn.js`; make sure to bundle from `lib/*` (complied js), or, alternately `src/*` (coffee) using a transform/loader.
99+
79100
## Manual installation
80101

81102
Download [zxcvbn.js](https://raw.githubusercontent.com/dropbox/zxcvbn/master/lib/zxcvbn.js).
@@ -172,7 +193,7 @@ Bug reports and pull requests welcome!
172193
git clone https://github.com/dropbox/zxcvbn.git
173194
```
174195

175-
zxcvbn is built with CoffeeScript, browserify, and uglify-js. CoffeeScript source lives in `src`, which gets compiled, bundled and minified into `lib/zxcvbn.js`.
196+
zxcvbn is built with CoffeeScript, browserify, and uglify-js. CoffeeScript source lives in `src`, which gets compiled, bundled and minified into `dist/zxcvbn.js`.
176197

177198
``` shell
178199
npm run build # builds lib/zxcvbn.js
@@ -183,6 +204,8 @@ For debugging, both `build` and `watch` output an external source map `lib/zxcvb
183204

184205
Two source files, `adjacency_graphs.coffee` and `frequency_lists.coffee`, are generated by python scripts in `data-scripts` that read raw data from the `data` directory.
185206

207+
For node developers, in addition to `dist`, the zxcvbn `npm` module includes a `lib` directory (hidden from git) that includes one compiled `.js` and `.js.map` file for every `.coffee` in `src`. See `prepublish` in `package.json` to learn more.
208+
186209
# Acknowledgments
187210

188211
Dropbox for supporting open source!

0 commit comments

Comments
 (0)