Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit 8754125

Browse files
committed
fill out readme with usage details
1 parent a8fa4ff commit 8754125

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

README.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,94 @@
22

33
Cypress preprocessor for bundling JavaScript via webpack
44

5-
## Install
5+
## Installation
66

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

99
```sh
1010
npm install --save-dev cypress-webpack-preprocessor
1111
```
1212

13+
## Usage
14+
15+
In your project's [plugins file](https://on.cypress.io/guides/plugins):
16+
17+
```javascript
18+
const webpack = require('@cypress/webpack-preprocessor')
19+
20+
module.exports = (register, config) => {
21+
register('on:spec:file:preprocessor', webpack(config))
22+
}
23+
```
24+
25+
## Options
26+
27+
Pass in options as the second argument to `webpack`:
28+
29+
```javascript
30+
module.exports = (register, config) => {
31+
const options = {
32+
// send in the options from your webpack.config.js, so it works the same
33+
// as your app's code
34+
webpackOptions: require('../../webpack.config'),
35+
watchOptions: {},
36+
}
37+
38+
register('on:spec:file:preprocessor', webpack(config, options))
39+
}
40+
```
41+
42+
### webpackOptions
43+
44+
Object of webpack options. Just `require` in the options from your `webpack.config.js` to use the same options as your app.
45+
46+
**Default**:
47+
48+
```javascript
49+
{
50+
module: {
51+
rules: [
52+
{
53+
test: /\.jsx?$/,
54+
exclude: [/node_modules/],
55+
use: [{
56+
loader: 'babel-loader',
57+
options: {
58+
presets: [
59+
'babel-preset-env',
60+
'babel-preset-react',
61+
],
62+
},
63+
}],
64+
},
65+
],
66+
},
67+
}
68+
```
69+
70+
### watchOptions
71+
72+
Object of options for watching. See [webpack's docs](https://webpack.github.io/docs/node.js-api.html#compiler).
73+
74+
**Default**: `{}`
75+
76+
## Modifying default options
77+
78+
The default options are provided as `webpack.defaultOptions` so they can be more easily modified.
79+
80+
If, for example, you want to update the options for the `babel-loader` to add the [stage-3 preset](https://babeljs.io/docs/plugins/preset-stage-3/), you could do the following:
81+
82+
```javascript
83+
const webpack = require('@cypress/webpack-preprocessor')
84+
85+
module.exports = (register, config) => {
86+
const options = webpack.defaultOptions
87+
options.webpackOptions.module.rules[0].use.options.presets.push('babel-preset-stage-3')
88+
89+
register('on:spec:file:preprocessor', webpack(config, options))
90+
}
91+
```
92+
1393
## License
1494

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

0 commit comments

Comments
 (0)