This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Need example transpiling es6 modules in node_modules folder #19
Comments
Solution
const browserify = require('@cypress/browserify-preprocessor')
module.exports = (on) => {
const options = browserify.defaultOptions
// print options to find babelify, it is inside transforms at index 1
// and it is [filename, options]
const babelOptions = options.browserifyOptions.transform[1][1]
babelOptions.global = true
// ignore all modules except files in lodash-es
babelOptions.ignore = [/\/node_modules\/(?!lodash-es\/)/]
// if you want to see the final options
// console.log('%o', babelOptions)
on('file:preprocessor', browserify(options))
} Example // use es6 module from node_modules
import { merge } from 'lodash-es';
// use our es6 module (works right out of the box)
import { foo } from './foo';
describe('Preprocessor Reproducer', () => {
it('test', () => {
expect(foo).to.equal('foo')
expect(merge({ foo: 'bar'}, { baz: 'bar'})).to.deep.equal({
foo: 'bar',
baz: 'bar'
})
})
}); there is noticeable transpile time for the test (this is why people recommend NOT to transpile es6), but the test passes |
For people seeking the same with typescript: until #61 is fixed, you can go with this workaround:
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
If the client wants to use
import { merge } from 'lodash-es';
then we need to show how to modify browserify options to transpilenode_modules
folderCypress 3.1.0
For cypress-io/cypress#2679
The text was updated successfully, but these errors were encountered: