JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 359740
  • Score
    100M100P100Q17283F
  • License MIT

Cypress preprocessor for bundling JavaScript via browserify

Package Exports

  • @cypress/browserify-preprocessor

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@cypress/browserify-preprocessor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Cypress Browserify Preprocessor

Cypress preprocessor for bundling JavaScript via browserify

Installation

Requires Node version 6.5.0 or above.

npm install --save-dev @cypress/browserify-preprocessor

Usage

In your project's plugins file:

const browserify = require('@cypress/browserify-preprocessor')

module.exports = (on) => {
  on('file:preprocessor', browserify())
}

Options

Pass in options as the second argument to browserify:

module.exports = (on) => {
  const options = {
    // options here
  }

  on('file:preprocessor', browserify(options))
}

browserifyOptions

Object of options passed to browserify.

If you pass one of these top-level options in, it will override the default. So if pass extensions: ['.cljs'], the default extensions (js, jsx, coffee, cjsx) will no longer be supported. If you wish to add to the supported extensions, read up on modifying the default options.

As long as the config passed from Cypress indicates that the plugin should watch files, watchify is automatically configured as a plugin, so there's no need to manually specify it.

Default:

{
  extensions: ['.js', '.jsx', '.coffee', '.cjsx'],
  transform: [
    [
      'cjsxify',
      {},
    ],
    [
      'babelify',
      {
        ast: false,
        babelrc: false,
        plugins: ['babel-plugin-add-module-exports'],
        presets: ['babel-preset-env', 'babel-preset-react'],
      },
    ],
  ],
  plugin: [],
  cache: {},
  packageCache: {},
}

watchifyOptions

Object of options passed to watchify

Default:

{
  ignoreWatch: [
    '**/.git/**',
    '**/.nyc_output/**',
    '**/.sass-cache/**',
    '**/bower_components/**',
    '**/coverage/**',
    '**/node_modules/**',
  ],
}

onBundle

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')
  }
})

Default: undefined

Modifying default options

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 loading, you could do the following:

const browserify = require('@cypress/browserify-preprocessor')

module.exports = (on) => {
  const options = browserify.defaultOptions
  options.transforms[1].options.babelrc = true

  on('file:preprocessor', browserify(options))
}

Contributing

Run all tests once:

npm test

Run tests in watch mode:

npm run test-watch

License

This project is licensed under the terms of the MIT license.