简体   繁体   English

Browserify - 避免输出绝对路径

[英]Browserify – Avoid output of absolute paths

In my Project I am using Browserify (programmatically with gulp). 在我的项目中,我使用Browserify(以编程方式使用gulp)。 In my main javascript file I am requiring modules A and B. A is also using B. In the output of Browserify I can find the absolute path to module A. 在我的主要javascript文件中,我需要模块A和B. A也在使用B.在Browserify的输出中,我可以找到模块A的绝对路径。

The output looks like this: 输出如下所示:

!function t(n,o,r){function e(s,a){if(!o[s]){if(!n[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=o[s]={exports:{}};n[s][0].call(f.exports,function(t){var o=n[s][1][t];return e(o?o:t)},f,f.exports,t,n,o,r)}return o[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)e(r[s]);return e}({1:[…]
    …
10:[function(t,n){n.exports=t(9)},{"/Applications/MAMP/htdocs/Projects/xyz/node_modules/moduleA/node_modules/moduleB/index.js":9}]},{},[1]);

Here is the relevant part of the gulpfile.js: 这是gulpfile.js的相关部分:

browserify(['./app/js/main.js'], {})
  .bundle()
  //Pass desired output filename to vinyl-source-stream
  .pipe(source('main.min.js'))
  //convert from streaming to buffered vinyl file object
  .pipe(buffer())
  // Start piping stream to tasks!
  .pipe(gulp.dest('app/js/'));

How can I avoid this? 我怎么能避免这个? I already tried several options of Browserify but it did not help. 我已经尝试了几种Browserify选项,但它没有帮助。 Side note: The two modules are being installed through npm but from GitHub because they are not published on npm. 旁注:这两个模块是通过npm安装的,但是来自GitHub,因为它们没有在npm上发布。

You need to set fullPaths to false . 您需要将fullPaths设置为false For additional compression, have a look at bundle-collapser : 有关其他压缩,请查看bundle-collapser

var collapse = require('bundle-collapser/plugin');

browserify(['./app/js/main.js'], { fullPaths: false })
  .plugin(collapse)
  .bundle()
  //Pass desired output filename to vinyl-source-stream
  .pipe(source('main.min.js'))
  //convert from streaming to buffered vinyl file object
  .pipe(buffer())
  // Start piping stream to tasks!
  .pipe(gulp.dest('app/js/'));

Also worth noting that you don't need to buffer the contents, unless you're piping through to uglify or some other non-streaming compatible transform. 另外值得注意的是,您不需要缓冲内容,除非您正在进行uglify或其他非流兼容转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM