最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using Gulp to run Webpack + Babel, but no presets are being applied - Stack Overflow

programmeradmin1浏览0评论

I'm using Gulp to run Webpack because some things that are trivial with Gulp are messy with Webpack, such as multiple outputs. However, babel-loader doesn't seem to be doing anything. When I have JSX in my scripts, I get a parse error. When I use ES6/7, nothing is transformed.

Here's the Gulp task:

gulp.task('js', function() {
    return gulp.src('js/*.js')
        .pipe(webpack({
            loaders: [{
                test: /.jsx?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                  presets: ['es2015', 'stage-0', 'react']
                }
            }],
            output: {
                filename: '[name].js'
            }
        }))
        .pipe(gulp.dest('public/js'));
});

Is there something I'm doing wrong?

I'm using Gulp to run Webpack because some things that are trivial with Gulp are messy with Webpack, such as multiple outputs. However, babel-loader doesn't seem to be doing anything. When I have JSX in my scripts, I get a parse error. When I use ES6/7, nothing is transformed.

Here's the Gulp task:

gulp.task('js', function() {
    return gulp.src('js/*.js')
        .pipe(webpack({
            loaders: [{
                test: /.jsx?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                  presets: ['es2015', 'stage-0', 'react']
                }
            }],
            output: {
                filename: '[name].js'
            }
        }))
        .pipe(gulp.dest('public/js'));
});

Is there something I'm doing wrong?

Share Improve this question edited Feb 22, 2016 at 6:26 loganfsmyth 162k31 gold badges346 silver badges258 bronze badges asked Feb 3, 2016 at 9:21 Leo JiangLeo Jiang 26.3k59 gold badges177 silver badges328 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

loaders shouldn't be at the top level of your configuration. It needs to be within module - try this:

gulp.task('js', function() {
    return gulp.src('js/*.js')
        .pipe(webpack({
            module: {
                loaders: [{
                    test: /.jsx?$/,
                    loader: 'babel-loader',
                    exclude: /node_modules/,
                    query: {
                        presets: ['es2015', 'stage-0', 'react']
                    }
                }]
            },
            output: {
                filename: '[name].js'
            }
        }))
        .pipe(gulp.dest('public/js'));
});
发布评论

评论列表(0)

  1. 暂无评论