When I compile markdown-symbols using Browserify 3.30.2 (browserify file.js -o bundle.js
), I get something like that :
!function(e){if("object"==typeof exports...[function(_dereq_,module,exports){ },{}],2:[function(_dereq_,module,exports){ ... ... [on line 8000] : function (str, start, len) { if (start < 0) start = str.length + start; return str.substr(start, len); } ; }).call(this,_dereq_("C:\\Users\\Me\\AppData\\Roaming\\npm\\node_modules\\browserify\\node_modules\\insert-module-globals\\node_modules\\process\\browser.js")) },{"C:\\Users\\Me\\AppData\\Roaming\\npm\\node_modules\\browserify\\node_modules\\insert-module-globals\\node_modules\\process\\browser.js":11}],14:[function(_dereq_,module,exports){ module.exports=_dereq_(3) },{}],15:[function(_dereq_,module,exports){ module.exports=_dereq_(4) },{"./support/isBuffer":14,"C:\\Users\\ME\\AppData\\Roaming\\npm\\node_modules\\browserify\\node_modules\\insert-module-globals\\node_modules\\process\\browser.js":11,"inherits":10}],16:[function(_dereq_,module,exports){ var frep = _dereq_('frep'); var file = _dereq_('fs-utils'); var delims = _dereq_('delims'); var _ = _dereq_('lodash'); ...
As you can see, there are absolute paths to my files here. Why ? How can I remove them ?
EDIT: here is my build.js
file
var browserify = require('browserify-middleware') fs = require('fs'); var b = browserify('./index.js', { 'opts.basedir': './' }); b({ // Mocks up express req and res headers: [] }, { getHeader: function () {}, setHeader: function () {}, send: function (a) { console.log('send', a); }, end: function (a) { //console.log('end', a.constructor.name); // fs.write('bundle.js', a, undefined, undefined, function (err) { console.log(a.toString()); //}); // a.pipe(fs.createWriteStream('bundle.js')); }, });
And to run node build > bundle.js
. same problem. If I replace basedir value by for instancee ihatebrowserify
there is an error about something not resolved.
This came across to me as well today. It turns out there's a boolean option --full-path
[0] now that solves the problem.
For example:
browserify -o bundle.js --full-path=false index.js
[0] https://github.com/substack/node-browserify/blob/master/bin/args.js
Almost 6 months later, and I've seen the same issue. Now I found a workaround that suited me, and others might benefit from it as well.
Google has given me this issue report: https://github.com/thlorenz/browserify-shim/issues/43 -- which reports this local system path disclosure on "browserify-shim", although it is a "browserify" issue from what I understood.
That issue suggests an workaround:
$ npm install -g intreq browser-pack browser-unpack $ browserify example/main.js -t browserify-shim | browser-unpack | intreq | browser-pack
I've tested this and was satisfied with the results. However I wanted to go further, and integrate this into my Gruntfile.js. The solution I found, tested and that made me happy is to use unpathify
:
Compress browserify require paths for better minification i.e. require('some/long/path') => require(1)
To use it, just install unpathify (npm install --save-dev unpathify
) and add it to your build:
grunt.initConfig({ browserify: { all: { files: { 'build/all.js': ['some/file.js'] } } }, unpathify: { all: { src: ['build/all.js'] } } // ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With