You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-4
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ To pull in updates and bug fixes:
53
53
bower update zxcvbn
54
54
```
55
55
56
-
## Node / npm / browserify
56
+
## Node / npm
57
57
58
58
zxcvbn works identically on the server.
59
59
@@ -64,8 +64,6 @@ $ node
64
64
> zxcvbn('Tr0ub4dour&3');
65
65
```
66
66
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
-
69
67
## RequireJS
70
68
71
69
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) {
76
74
});
77
75
```
78
76
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`:
*`--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.
@@ -172,7 +193,7 @@ Bug reports and pull requests welcome!
172
193
gitclonehttps://github.com/dropbox/zxcvbn.git
173
194
```
174
195
175
-
zxcvbn isbuiltwith CoffeeScript, browserify, and uglify-js. CoffeeScriptsource lives in`src`, which gets compiled, bundled and minified into `lib/zxcvbn.js`.
196
+
zxcvbn isbuiltwith CoffeeScript, browserify, and uglify-js. CoffeeScriptsource lives in`src`, which gets compiled, bundled and minified into `dist/zxcvbn.js`.
176
197
177
198
``` shell
178
199
npmrun build # builds lib/zxcvbn.js
@@ -183,6 +204,8 @@ For debugging, both `build` and `watch` output an external source map `lib/zxcvb
183
204
184
205
Twosource files, `adjacency_graphs.coffee` and `frequency_lists.coffee`, are generated by python scripts in `data-scripts` that read raw data from the `data` directory.
185
206
207
+
Fornode developers, inaddition 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`tolearn more.
0 commit comments