Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide a specif builtin version #1980

Open
vesparny opened this issue Oct 1, 2020 · 2 comments
Open

provide a specif builtin version #1980

vesparny opened this issue Oct 1, 2020 · 2 comments

Comments

@vesparny
Copy link

vesparny commented Oct 1, 2020

Hi, is there any chance to specify a specific version of a builtin?
I need to create a bundle which uses [email protected]
thanks

@goto-bus-stop
Copy link
Member

That version of buffer is extremely old…do you need to support IE6 or something? 😕

If you install your desired version using npm, you can use the -r flag to override any dependency by name.

browserify -r buffer/:buffer main.js

or with the API:

browserify('main.js')
  .require('buffer/', { expose: 'buffer' })

The trailing / is important: it forces the resolver to look at the files and dependencies in your project instead of at node.js core modules.

@vesparny
Copy link
Author

vesparny commented Nov 12, 2020

Hi @goto-bus-stop

thanks for the support.
I ended up doing something similar:

const browserify = require('browserify')
const watchify = require('watchify')
const errorify = require('errorify')
const fs = require('fs')

const b = browserify('./src/index.js', {
  builtins: {
    buffer: require.resolve('buffer/'),
    _process: require.resolve('process/browser'),
    events: require.resolve('events/'),
    util: require.resolve('util/util.js'),
    stream: require.resolve('stream-browserify'),
    timers: require.resolve('timers-browserify'),
    string_decoder: require.resolve('string_decoder/')
  },
  standalone: 'lib',
  plugin: process.env.NODE_ENV ? [watchify, errorify] : []
})

const bundle = () => {
  b.bundle()
    .on('error', console.error)
    .pipe(fs.createWriteStream('dist/index.js'))
}

if (process.env.NODE_ENV) {
  b.on('update', bundle)
}

bundle()

it is something similar to what you proposed I guess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants