1 | const transformTools = require('browserify-transform-tools')
|
2 |
|
3 | const nodeRequire = '/node'
|
4 | const browserRequire = '/browser'
|
5 |
|
6 | module.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 | )
|