【问题标题】:Gulpfile doesn't create bundle.jsGulpfile 不会创建 bundle.js
【发布时间】:2016-06-19 00:15:07
【问题描述】:

我的 gulpfile 有一些问题

"use strict"

var gulp = require("gulp")
var browserify = require("browserify")
var source = require("vinyl-source-stream")
var livereload = require('gulp-livereload')
var watchify = require('watchify')

gulp.task("default", () => {
    livereload.listen()
    var bundler = browserify("./src/components/index.jsx")
        .plugin(watchify, {ignoreWatch: './src/components/*'})
        .transform("babelify", {presets: ["es2015", "react"]})
    bundle(bundler)
    bundler.on('update', function () {
        bundle(bundler)
    })
})

function bundle(bundler) {

  bundler
    .bundle()
    .pipe(source('bundle.js')) // Set source name
    .pipe(gulp.dest("./public/dist"))
    .pipe(livereload()); // Reload the view in the browser
}

当我使用gulp执行它时,我收到以下消息

[02:06:23] 使用 gulpfile ~/react-rpi/gulpfile.js

[02:06:23] 开始

'default'... [02:06:23] 24 ms 后完成'default'

但是 bundle.js 没有被创建。有什么钥匙吗?提前致谢!

【问题讨论】:

    标签: reactjs gulp


    【解决方案1】:

    你为什么不试试这个?

    function bundle(bundler) {  
        return bundler.bundle().on('error', function (err) {
            console.error(err.message)
            this.emit('end')
        })
        .pipe(source('bundle.js'))
        .pipe(buffer())
        .pipe(plugins.sourcemaps.init({ loadMaps: true }))
        .pipe(plugins.sourcemaps.write('./'))
        .pipe(gulp.dest('./public/dist/js/'))
        .pipe(plugins.livereload()) 
    }
    

    然后你就可以看到发生了什么

    【讨论】:

    猜你喜欢
    • 2018-06-20
    • 2017-12-12
    • 2015-09-22
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多