1. <i id='PTie2'><tr id='PTie2'><dt id='PTie2'><q id='PTie2'><span id='PTie2'><b id='PTie2'><form id='PTie2'><ins id='PTie2'></ins><ul id='PTie2'></ul><sub id='PTie2'></sub></form><legend id='PTie2'></legend><bdo id='PTie2'><pre id='PTie2'><center id='PTie2'></center></pre></bdo></b><th id='PTie2'></th></span></q></dt></tr></i><div id='PTie2'><tfoot id='PTie2'></tfoot><dl id='PTie2'><fieldset id='PTie2'></fieldset></dl></div>
    2. <legend id='PTie2'><style id='PTie2'><dir id='PTie2'><q id='PTie2'></q></dir></style></legend>

      <tfoot id='PTie2'></tfoot>
      • <bdo id='PTie2'></bdo><ul id='PTie2'></ul>

        <small id='PTie2'></small><noframes id='PTie2'>

        如何在 Gulp 中使用 Browserify 丑化输出?

        时间:2023-05-27
          <bdo id='HR4tj'></bdo><ul id='HR4tj'></ul>
          1. <legend id='HR4tj'><style id='HR4tj'><dir id='HR4tj'><q id='HR4tj'></q></dir></style></legend>

            <small id='HR4tj'></small><noframes id='HR4tj'>

            <i id='HR4tj'><tr id='HR4tj'><dt id='HR4tj'><q id='HR4tj'><span id='HR4tj'><b id='HR4tj'><form id='HR4tj'><ins id='HR4tj'></ins><ul id='HR4tj'></ul><sub id='HR4tj'></sub></form><legend id='HR4tj'></legend><bdo id='HR4tj'><pre id='HR4tj'><center id='HR4tj'></center></pre></bdo></b><th id='HR4tj'></th></span></q></dt></tr></i><div id='HR4tj'><tfoot id='HR4tj'></tfoot><dl id='HR4tj'><fieldset id='HR4tj'></fieldset></dl></div>

              <tfoot id='HR4tj'></tfoot>

                <tbody id='HR4tj'></tbody>

                  本文介绍了如何在 Gulp 中使用 Browserify 丑化输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我试图在 Gulp 中对 Browserify 的输出进行 uglify,但它不起作用.

                  I tried to uglify output of Browserify in Gulp, but it doesn't work.

                  gulpfile.js

                  var browserify = require('browserify');
                  var gulp = require('gulp');
                  var uglify = require('gulp-uglify');
                  var source = require('vinyl-source-stream');
                  
                  gulp.task('browserify', function() {
                      return browserify('./source/scripts/app.js')
                          .bundle()
                          .pipe(source('bundle.js'))
                          .pipe(uglify()) // ???
                          .pipe(gulp.dest('./build/scripts'));
                  });
                  

                  据我了解,我无法按照以下步骤进行操作.我需要在一个管道中制作以保留序列吗?

                  As I understand I cannot make it in steps as below. Do I need to make in one pipe to preserve the sequence?

                  gulp.task('browserify', function() {
                      return browserify('./source/scripts/app.js')
                          .bundle()
                          .pipe(source('bundle.js'))
                          .pipe(uglify()) // ???
                          .pipe(gulp.dest('./source/scripts'));
                  });
                  
                  gulp.task('scripts', function() {
                      return grunt.src('./source/scripts/budle.js')
                          .pipe(uglify())
                          .pipe(gulp.dest('./build/scripts'));
                  });
                  
                  gulp.task('default', function(){
                      gulp.start('browserify', 'scripts');
                  });
                  

                  推荐答案

                  其实你们已经很接近了,除了一件事:

                  You actually got pretty close, except for one thing:

                  • 您需要将 source() 给出的 streaming 乙烯基文件对象转换为 vinyl-buffer 因为 gulp-uglify(和大多数 gulp 插件)适用于缓冲乙烯基文件对象
                  • you need to convert the streaming vinyl file object given by source() with vinyl-buffer because gulp-uglify (and most gulp plugins) works on buffered vinyl file objects

                  所以你会用这个来代替

                  var browserify = require('browserify');
                  var gulp = require('gulp');
                  var uglify = require('gulp-uglify');
                  var source = require('vinyl-source-stream');
                  var buffer = require('vinyl-buffer');
                  
                  gulp.task('browserify', function() {
                    return browserify('./source/scripts/app.js')
                      .bundle()
                      .pipe(source('bundle.js')) // gives streaming vinyl file object
                      .pipe(buffer()) // <----- convert from streaming to buffered vinyl file object
                      .pipe(uglify()) // now gulp-uglify works 
                      .pipe(gulp.dest('./build/scripts'));
                  });
                  

                  或者,您可以选择使用 vinyl-transform 代替它为您处理 streamingbuffered 乙烯基文件对象,例如所以

                  Or, you can choose to use vinyl-transform instead which takes care of both streaming and buffered vinyl file objects for you, like so

                  var gulp = require('gulp');
                  var browserify = require('browserify');
                  var transform = require('vinyl-transform');
                  var uglify = require('gulp-uglify');
                  
                  
                  gulp.task('build', function () {
                  
                    // use `vinyl-transform` to wrap the regular ReadableStream returned by `b.bundle();` with vinyl file object
                    // so that we can use it down a vinyl pipeline
                    // while taking care of both streaming and buffered vinyl file objects
                    var browserified = transform(function(filename) {
                      // filename = './source/scripts/app.js' in this case
                      return browserify(filename)
                        .bundle();
                    });
                  
                    return gulp.src(['./source/scripts/app.js']) // you can also use glob patterns here to browserify->uglify multiple files
                      .pipe(browserified)
                      .pipe(uglify())
                      .pipe(gulp.dest('./build/scripts'));
                  });
                  

                  以上两种方法都可以达到相同的效果.

                  Both of the above recipes will achieve the same thing.

                  这只是关于您希望如何管理管道(在常规 NodeJS 流和流式乙烯基文件对象和缓冲乙烯基文件对象之间进行转换)

                  Its just about how you want to manage your pipes (converting between regular NodeJS Streams and streaming vinyl file objects and buffered vinyl file objects)

                  我写了一篇关于使用 gulp + browserify 和不同方法的较长文章:https://medium.com/@sogko/gulp-browserify-the-gulp-y-way-bb359b3f9623

                  I've written a longer article regarding using gulp + browserify and different approaches at: https://medium.com/@sogko/gulp-browserify-the-gulp-y-way-bb359b3f9623

                  这篇关于如何在 Gulp 中使用 Browserify 丑化输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我可以从 ServiceWorker 中的外部 JS 文件调用方法吗 下一篇:如何调试 Gulp 任务?

                  相关文章

                  最新文章

                • <tfoot id='rLN57'></tfoot>
                    • <bdo id='rLN57'></bdo><ul id='rLN57'></ul>
                    <i id='rLN57'><tr id='rLN57'><dt id='rLN57'><q id='rLN57'><span id='rLN57'><b id='rLN57'><form id='rLN57'><ins id='rLN57'></ins><ul id='rLN57'></ul><sub id='rLN57'></sub></form><legend id='rLN57'></legend><bdo id='rLN57'><pre id='rLN57'><center id='rLN57'></center></pre></bdo></b><th id='rLN57'></th></span></q></dt></tr></i><div id='rLN57'><tfoot id='rLN57'></tfoot><dl id='rLN57'><fieldset id='rLN57'></fieldset></dl></div>
                  1. <legend id='rLN57'><style id='rLN57'><dir id='rLN57'><q id='rLN57'></q></dir></style></legend>

                    <small id='rLN57'></small><noframes id='rLN57'>