Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit 55831b0

Browse files
committed
fill out readme with usage details
1 parent 0d7a99b commit 55831b0

File tree

1 file changed

+116
-2
lines changed

1 file changed

+116
-2
lines changed

README.md

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,128 @@
22

33
Cypress preprocessor for bundling JavaScript via browserify
44

5-
## Install
5+
## Installation
66

77
Requires [Node](https://nodejs.org/en/) version 6 or above.
88

99
```sh
10-
npm install --save-dev cypress-browserify-preprocessor
10+
npm install --save-dev @cypress/browserify-preprocessor
1111
```
1212

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+
13127
## License
14128

15129
This project is licensed under the terms of the [MIT license](/LICENSE.md).

0 commit comments

Comments
 (0)