美文网首页
如何新增 gulp 工具以 gulp-react 为例

如何新增 gulp 工具以 gulp-react 为例

作者: Transnet2014 | 来源:发表于2017-04-19 18:50 被阅读15次

    返回导航

    #278

    You need to create javascript files using react() first and write them to a temporary directory, and then inject them with wiredep, you can't do all in a single step.

    Create a task to compile JSX to JavaScript ...

    gulp.task('jsx', function () {
     return gulp.src([
        paths.src + '/{app,components}/**/*.jsx'
      ]).pipe(react())
     .dist(paths.tmp + '/jsx');
    

    And then depend from this task to wiredep generated javascript files in index.html

    gulp.task('inject', ['styles', 'jsx'], function () { // Depend on jsx compile task
    ....
     var injectJSX = gulp.src([
        paths.tmp + '/jsx/**/*.js' // *.js because react() compiles to javascript
      ]).pipe(react());
    ...
    return gulp.src(paths.src + '/*.html')
        .pipe($.inject(injectStyles, injectOptions))
        .pipe($.inject(injectJSX, injectOptions))
        .pipe($.inject(injectScripts, injectOptions))
        .pipe(wiredep(wiredepOptions))
        ...
    );
    ...
    

    I didn't try, it may have caveats, but idea is there.

    返回导航

    相关文章

      网友评论

          本文标题:如何新增 gulp 工具以 gulp-react 为例

          本文链接:https://www.haomeiwen.com/subject/rmphzttx.html