<bdo id='nL7Tc'></bdo><ul id='nL7Tc'></ul>

  1. <small id='nL7Tc'></small><noframes id='nL7Tc'>

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

      将 Gulp glob 链接到浏览器化转换

      时间:2023-05-28
        <tfoot id='nnvTr'></tfoot>
            <tbody id='nnvTr'></tbody>

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

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

              2. 本文介绍了将 Gulp glob 链接到浏览器化转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我有一个项目,其中包含几个相对不相交的页面,每个页面都包含自己的入口点脚本.这些脚本需要其他一些使用commonjs语法的脚本,需要经过6to5转换并被browserify打包.

                I have a project with a few relatively disjoint pages, each including their own entry point script. These scripts require a number of others using commonjs syntax, and need to be transformed by 6to5 and bundled by browserify.

                我想设置一个 gulp 任务来捕获所有匹配模式的文件并将它们传递给捆绑程序,但我不确定如何将文件从 gulp.src 传递到浏览(文件名).

                I would like to set up a gulp task that captures all the files matching a pattern and passes them on to the bundler, but I'm not sure how to pass files from gulp.src to browserify(filename).

                我的 gulpfile 看起来像:

                My gulpfile looks like:

                var gulp = require("gulp");
                var browserify = require("browserify");
                var to5browserify = require("6to5-browserify");
                var source = require("vinyl-source-stream");
                
                var BUNDLES = [
                    "build.js",
                    "export.js",
                    "main.js"
                ];
                
                gulp.task("bundle", function () {
                    /* Old version, using glob:
                    return gulp.src("src/** /*.js")
                        .pipe(sixto5())
                        .pipe(gulp.dest("dist"));
                    */
                
                    // New version, using array:
                    return BUNDLES.map(function (bundle) {
                        return browserify("./src/" + bundle, {debug: true})
                            .transform(to5browserify)
                            .bundle()
                            .pipe(source(bundle))
                            .pipe(gulp.dest("./dist"));
                    });
                });
                
                gulp.task("scripts", ["bundle"]);
                
                gulp.task("html", function () {
                    return gulp.src("src/**/*.html")
                        .pipe(gulp.dest("dist"));
                });
                
                gulp.task("styles", function () {
                    return gulp.src("src/**/*.css")
                        .pipe(gulp.dest("dist"));
                });
                
                gulp.task("default", ["scripts", "html", "styles"]);
                

                这似乎可行,但不可维护:我将很快添加更多脚本,并且不想每次都将它们添加到数组中.

                This seems to work, but isn't maintainable: I'll be adding more scripts relatively soon, and don't want to add them to the array every time.

                我尝试在 browserify 调用中使用 gulp.src(glob).pipe 并在调用后使用管道 (此处显示)和 gulp.src(glob).map(方法不存在).

                I've tried using gulp.src(glob).pipe within the browserify call and piping after calling (shown here), and gulp.src(glob).map (method doesn't exist).

                如何将 gulp.src 与 browserify 等基于名称的转换器链接起来?

                How can you chain gulp.src with a name-based transformer like browserify?

                推荐答案

                使用through2制作一次性的自定义插件流,可以完成所有繁琐的工作.

                Use through2 to make a one-off custom plugin stream that does all of the dirty work.

                不幸的是 vinyl-transformvinyl-source-stream 以及随之而来的解决方案缺陷,所以我们必须去定制一些东西.

                Unfortanately vinyl-transform and vinyl-source-stream and the solutions that go along with those have flaws so we have to go for something custom.

                var gulp = require('gulp');
                var through = require('through2');
                var browserify = require('browserify');
                
                gulp.task('bundle', function() {
                    var browserified = function() {
                        return through.obj(function(chunk, enc, callback) {
                            if(chunk.isBuffer()) {
                                var b = browserify(chunk.path);
                                    // Any custom browserify stuff should go here
                                    //.transform(to5browserify);
                
                                chunk.contents = b.bundle();
                
                                this.push(chunk);
                
                            }
                            callback();
                        });
                    };
                
                    return gulp.src(['./src/**/*.js'])
                        .pipe(browserified())
                        .pipe(gulp.dest('dest'));
                });
                

                这篇关于将 Gulp glob 链接到浏览器化转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:我可以将 gulp livereload 设置为在所有文件编译后运 下一篇:javascript, gulp, 观看, 改变

                相关文章

                最新文章

                  <tfoot id='4Muxb'></tfoot>
                1. <legend id='4Muxb'><style id='4Muxb'><dir id='4Muxb'><q id='4Muxb'></q></dir></style></legend>

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

                    <small id='4Muxb'></small><noframes id='4Muxb'>