UNPKG

606 BJavaScriptView Raw
1const transformTools = require('browserify-transform-tools')
2
3const nodeRequire = '/node'
4const browserRequire = '/browser'
5
6module.exports = transformTools.makeRequireTransform(
7 'nodeToBrowserRequireTransform',
8 { evaluateArguments: true },
9 function (args, opts, cb) {
10 const requireArg = args[0]
11 const endsWithNodeRequire =
12 requireArg.slice(-nodeRequire.length) === nodeRequire
13 if (endsWithNodeRequire) {
14 const newRequireArg = requireArg.replace(nodeRequire, browserRequire)
15 return cb(null, "require('" + newRequireArg + "')")
16 } else {
17 return cb()
18 }
19 }
20)