• <bdo id='syxun'></bdo><ul id='syxun'></ul>

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

        Gulp + babelify + browserify 问题

        时间:2023-05-28

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

              • <bdo id='7XCbt'></bdo><ul id='7XCbt'></ul>

                <small id='7XCbt'></small><noframes id='7XCbt'>

                <tfoot id='7XCbt'></tfoot>

                    <tbody id='7XCbt'></tbody>

                  本文介绍了Gulp + babelify + browserify 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试使用 browserify 和 babelify 创建一个 gulp 任务.这是任务:

                  I'm trying to create a gulp task with browserify and babelify. Here is the task:

                  var gulp = require('gulp');
                  var browserify = require('gulp-browserify');
                  var source = require('vinyl-source-stream');
                  var babelify = require('babelify');
                  
                  gulp.task('js', function () {
                      browserify('./resources/js/*.js')
                          .transform(babelify)
                          .bundle()
                          .pipe(source('*.js'))
                          .pipe(gulp.dest('./public/js'));
                  });
                  

                  我找到了一些示例代码,尝试使用它们,但结果总是一样.

                  I found a few sample code, tried to use them, but the result was always the same.

                  当我运行任务并保存我的 example.js 文件时,出现以下错误:

                  When i run the task, and save my example.js file, the following error occurs:

                  TypeError: browserify(...).transform 不是函数

                  我做错了什么?

                  推荐答案

                  你混淆了 browserifygulp-browserify 的 API.

                  You're mixing up the API for browserify and gulp-browserify.

                  从 gulp-browserify docs,您需要执行以下操作:

                  From the gulp-browserify docs, you'll want to do something like this:

                  var gulp = require('gulp')
                  var browserify = require('gulp-browserify')
                  
                  gulp.task('js', function () {
                    gulp.src('./resources/js/*.js')
                      .pipe(browserify({
                        transform: ['babelify'],
                      }))
                      .pipe(gulp.dest('./public/js'))
                  });
                  

                  <小时>

                  自从第一次回答这个问题以来,gulp-browserify 已被放弃 并且 gulp 已经发展了很多.如果您想使用更新版本的 gulp 实现相同的功能,您可以 遵循 gulp 团队提供的指南.


                  Since this question was first answered, gulp-browserify has been abandoned and gulp has evolved a great deal. If you'd like to achieve the same thing with a newer version of gulp, you can follow the guides provided by the gulp team.

                  你最终会得到如下的结果:

                  You'll end up with something like the following:

                  var browserify = require('browserify');
                  var babelify = require('babelify');
                  var gulp = require('gulp');
                  var source = require('vinyl-source-stream');
                  var buffer = require('vinyl-buffer');
                  var sourcemaps = require('gulp-sourcemaps');
                  var util = require('gulp-util');
                  
                  gulp.task('default', function () {
                    var b = browserify({
                      entries: './resources/test.js',
                      debug: true,
                      transform: [babelify.configure({
                        presets: ['es2015']
                      })]
                    });
                  
                    return b.bundle()
                      .pipe(source('./resources/test.js'))
                      .pipe(buffer())
                      .pipe(sourcemaps.init({ loadMaps: true }))
                        // Add other gulp transformations (eg. uglify) to the pipeline here.
                        .on('error', util.log)
                      .pipe(sourcemaps.write('./'))
                      .pipe(gulp.dest('./public/js/'));
                  });
                  

                  这篇关于Gulp + babelify + browserify 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在没有构建工具(如 grunt 和 gulp)的情况下使用 J 下一篇:如何在 gulp 中的任务中获取任务名称

                  相关文章

                  最新文章

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

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

                      <bdo id='bPGxQ'></bdo><ul id='bPGxQ'></ul>
                    <tfoot id='bPGxQ'></tfoot>