|
2 | 2 |
|
3 | 3 | Cypress preprocessor for bundling JavaScript via browserify |
4 | 4 |
|
5 | | -## Install |
| 5 | +## Installation |
6 | 6 |
|
7 | 7 | Requires [Node](https://nodejs.org/en/) version 6 or above. |
8 | 8 |
|
9 | 9 | ```sh |
10 | | -npm install --save-dev cypress-browserify-preprocessor |
| 10 | +npm install --save-dev @cypress/browserify-preprocessor |
11 | 11 | ``` |
12 | 12 |
|
| 13 | +## Usage |
| 14 | + |
| 15 | +In your project's [plugins file](https://on.cypress.io/guides/plugins): |
| 16 | + |
| 17 | +```javascript |
| 18 | +const browserify = require('@cypress/browserify-preprocessor') |
| 19 | + |
| 20 | +module.exports = (register, config) => { |
| 21 | + register('on:spec:file:preprocessor', browserify(config)) |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +## Options |
| 26 | + |
| 27 | +Pass in options as the second argument to `browserify`: |
| 28 | + |
| 29 | +```javascript |
| 30 | +module.exports = (register, config) => { |
| 31 | + const options = { |
| 32 | + extensions: [], |
| 33 | + watchOptions: {}, |
| 34 | + transforms: [], |
| 35 | + onBundle () {}, |
| 36 | + } |
| 37 | + |
| 38 | + register('on:spec:file:preprocessor', browserify(config, options)) |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +### extensions |
| 43 | + |
| 44 | +Array of file extensions to supported. |
| 45 | + |
| 46 | +**Default**: |
| 47 | + |
| 48 | +```javascript |
| 49 | +['.js', '.jsx', '.coffee', '.cjsx'] |
| 50 | +``` |
| 51 | + |
| 52 | +### watchOptions |
| 53 | + |
| 54 | +Object of options passed to [watchify](https://github.com/browserify/watchify#options) |
| 55 | + |
| 56 | +**Default**: |
| 57 | + |
| 58 | +```javascript |
| 59 | +{ |
| 60 | + ignoreWatch: [ |
| 61 | + '**/.git/**', |
| 62 | + '**/.nyc_output/**', |
| 63 | + '**/.sass-cache/**', |
| 64 | + '**/bower_components/**', |
| 65 | + '**/coverage/**', |
| 66 | + '**/node_modules/**', |
| 67 | + ], |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +### transforms |
| 72 | + |
| 73 | +Array of transforms. Each item is an object with a `transform` set to the path to a transform package or the required module itself and `options` set to the options for that transform. |
| 74 | + |
| 75 | +**Default**: |
| 76 | + |
| 77 | +```javascript |
| 78 | +[ |
| 79 | + { |
| 80 | + transform: 'cjsxify', |
| 81 | + options: {}, |
| 82 | + }, |
| 83 | + { |
| 84 | + transform: 'babelify', |
| 85 | + options: { |
| 86 | + ast: false, |
| 87 | + babelrc: false, |
| 88 | + plugins: ['babel-plugin-add-module-exports'], |
| 89 | + presets: ['babel-preset-env', 'babel-preset-react'], |
| 90 | + }, |
| 91 | + }, |
| 92 | +] |
| 93 | +``` |
| 94 | + |
| 95 | +### onBundle |
| 96 | + |
| 97 | +A function that is called with the [browserify bundle](https://github.com/browserify/browserify#browserifyfiles--opts). This allows you to specify external files and plugins. See the [browserify docs](https://github.com/browserify/browserify#baddfile-opts) for methods available. |
| 98 | + |
| 99 | +```javascript |
| 100 | +browserify({ |
| 101 | + onBundle (bundle) { |
| 102 | + bundle.external('react') |
| 103 | + bundle.plugin('some-plugin') |
| 104 | + } |
| 105 | +}) |
| 106 | +``` |
| 107 | + |
| 108 | +## Modifying default options |
| 109 | + |
| 110 | +The default options are provided as `browserify.defaultOptions` so they can be more easily modified. |
| 111 | + |
| 112 | +If, for example, you want to update the options for the `babelify` transform to turn on `babelrc`, you could do the following: |
| 113 | + |
| 114 | +```javascript |
| 115 | +const browserify = require('@cypress/browserify-preprocessor') |
| 116 | + |
| 117 | +module.exports = (register, config) => { |
| 118 | + const options = browserify.options |
| 119 | + options.transforms[1].options.babelrc = true |
| 120 | + |
| 121 | + register('on:spec:file:preprocessor', browserify(config, options)) |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +**Default**: `undefined` |
| 126 | + |
13 | 127 | ## License |
14 | 128 |
|
15 | 129 | This project is licensed under the terms of the [MIT license](/LICENSE.md). |
0 commit comments