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

Commit ab111fd

Browse files
Merge pull request #97 from cypress-io/update-documentation-for-10.0
docs: update readme with 10.0 instructions
2 parents 2b1c1f4 + 842a15a commit ab111fd

File tree

1 file changed

+52
-30
lines changed

1 file changed

+52
-30
lines changed

README.md

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,51 @@ npm install --save-dev @cypress/browserify-preprocessor
1818

1919
## Usage
2020

21+
### Prior to Cypress 10.0
22+
2123
In your project's [plugins file](https://on.cypress.io/plugins-guide):
2224

2325
```javascript
24-
const browserify = require('@cypress/browserify-preprocessor')
26+
const browserify = require("@cypress/browserify-preprocessor");
2527

2628
module.exports = (on) => {
27-
on('file:preprocessor', browserify())
28-
}
29+
on("file:preprocessor", browserify());
30+
};
31+
```
32+
33+
### Cypress 10.0 and Beyond
34+
35+
In your project's [cypress config](https://on.cypress.io/plugins-api):
36+
37+
```javascript
38+
const { defineConfig } = require("cypress");
39+
const browserify = require("@cypress/browserify-preprocessor");
40+
41+
module.exports = defineConfig({
42+
e2e: {
43+
setupNodeEvents(on, config) {
44+
on("file:preprocessor", browserify());
45+
},
46+
},
47+
component: {
48+
setupNodeEvents(on, config) {
49+
on("file:preprocessor", browserify());
50+
},
51+
},
52+
});
2953
```
3054

3155
## Options
3256

3357
Pass in options as the second argument to `browserify`:
3458

3559
```javascript
36-
module.exports = (on) => {
60+
{
3761
const options = {
3862
// options here
39-
}
63+
};
4064

41-
on('file:preprocessor', browserify(options))
65+
on("file:preprocessor", browserify(options));
4266
}
4367
```
4468

@@ -50,12 +74,10 @@ Object of options passed to [browserify](https://github.com/browserify/browserif
5074
// example
5175
browserify({
5276
browserifyOptions: {
53-
extensions: ['.js', '.ts'],
54-
plugin: [
55-
['tsify']
56-
]
57-
}
58-
})
77+
extensions: [".js", ".ts"],
78+
plugin: [["tsify"]],
79+
},
80+
});
5981
```
6082

6183
If you pass one of the top-level options in (`extensions`, `transform`, etc), it will override the default. In the above example, browserify will process `.js` and `.ts` files, but not `.jsx` or `.coffee`. If you wish to add to or modify existing options, read about [modifying the default options](#modifying-default-options).
@@ -80,7 +102,7 @@ Source maps are always enabled unless explicitly disabled by specifying `debug:
80102
ast: false,
81103
babelrc: false,
82104
plugins: [
83-
'@babel/plugin-transform-modules-commonjs',
105+
'@babel/plugin-transform-modules-commonjs',
84106
'@babel/plugin-proposal-class-properties',
85107
'@babel/plugin-proposal-object-rest-spread',
86108
'@babel/plugin-transform-runtime',
@@ -99,7 +121,7 @@ Source maps are always enabled unless explicitly disabled by specifying `debug:
99121
}
100122
```
101123

102-
*Note*: `cache` and `packageCache` are always set to `{}` and cannot be overridden. Otherwise, file watching would not function correctly.
124+
_Note_: `cache` and `packageCache` are always set to `{}` and cannot be overridden. Otherwise, file watching would not function correctly.
103125

104126
### watchifyOptions
105127

@@ -109,9 +131,9 @@ Object of options passed to [watchify](https://github.com/browserify/watchify#op
109131
// example
110132
browserify({
111133
watchifyOptions: {
112-
delay: 500
113-
}
114-
})
134+
delay: 500,
135+
},
136+
});
115137
```
116138

117139
**Default**:
@@ -136,12 +158,12 @@ A function that is called with the [browserify instance](https://github.com/brow
136158
```javascript
137159
// example
138160
browserify({
139-
onBundle (bundle) {
140-
bundle.external('react')
141-
bundle.plugin('some-plugin')
142-
bundle.ignore('pg-native')
143-
}
144-
})
161+
onBundle(bundle) {
162+
bundle.external("react");
163+
bundle.plugin("some-plugin");
164+
bundle.ignore("pg-native");
165+
},
166+
});
145167
```
146168

147169
### typescript
@@ -150,8 +172,8 @@ When the path to the TypeScript package is given, Cypress will automatically tra
150172

151173
```javascript
152174
browserify({
153-
typescript: require.resolve('typescript')
154-
})
175+
typescript: require.resolve("typescript"),
176+
});
155177
```
156178

157179
**Default**: `undefined`
@@ -163,13 +185,13 @@ The default options are provided as `browserify.defaultOptions` so they can be m
163185
If, for example, you want to update the options for the `babelify` transform to turn on `babelrc` loading, you could do the following:
164186

165187
```javascript
166-
const browserify = require('@cypress/browserify-preprocessor')
188+
const browserify = require("@cypress/browserify-preprocessor");
167189

168-
module.exports = (on) => {
169-
const options = browserify.defaultOptions
170-
options.browserifyOptions.transform[1][1].babelrc = true
190+
{
191+
const options = browserify.defaultOptions;
192+
options.browserifyOptions.transform[1][1].babelrc = true;
171193

172-
on('file:preprocessor', browserify(options))
194+
on("file:preprocessor", browserify(options));
173195
}
174196
```
175197

0 commit comments

Comments
 (0)