Cypress preprocessor for bundling JavaScript via browserify
Requires Node version 6 or above.
npm install --save-dev @cypress/browserify-preprocessorIn your project's plugins file:
const browserify = require('@cypress/browserify-preprocessor')
module.exports = (register, config) => {
register('on:spec:file:preprocessor', browserify(config))
}Pass in options as the second argument to browserify:
module.exports = (register, config) => {
const options = {
extensions: [],
watchOptions: {},
transforms: [],
onBundle () {},
}
register('on:spec:file:preprocessor', browserify(config, options))
}Array of file extensions to supported.
Default:
['.js', '.jsx', '.coffee', '.cjsx']Object of options passed to watchify
Default:
{
ignoreWatch: [
'**/.git/**',
'**/.nyc_output/**',
'**/.sass-cache/**',
'**/bower_components/**',
'**/coverage/**',
'**/node_modules/**',
],
}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.
Default:
[
{
transform: 'cjsxify',
options: {},
},
{
transform: 'babelify',
options: {
ast: false,
babelrc: false,
plugins: ['babel-plugin-add-module-exports'],
presets: ['babel-preset-env', 'babel-preset-react'],
},
},
]A function that is called with the browserify bundle. This allows you to specify external files and plugins. See the browserify docs for methods available.
browserify({
onBundle (bundle) {
bundle.external('react')
bundle.plugin('some-plugin')
}
})The default options are provided as browserify.defaultOptions so they can be more easily modified.
If, for example, you want to update the options for the babelify transform to turn on babelrc, you could do the following:
const browserify = require('@cypress/browserify-preprocessor')
module.exports = (register, config) => {
const options = browserify.options
options.transforms[1].options.babelrc = true
register('on:spec:file:preprocessor', browserify(config, options))
}Default: undefined
This project is licensed under the terms of the MIT license.