search

Home  >  Q&A  >  body text

javascript - When gulp executes the webpack task, the file is generated and the loader is not executed.

gulpfile.js configuration file

var gulp = require('gulp');
var webpack = require('webpack-stream');
var named = require('vinyl-named');

gulp.task('default', function () {
    return gulp.src('./resource/js/app.js')
        .pipe(webpack( require('./webpack.config.js') ))
        .pipe(gulp.dest('./public/js/'));
});

webpack.config.js configuration file

module.exports = {
    entry : './resource/js/app.js',
    output : {
        filename : 'bundle.js'
    },
    module : {
        rules : [
            {
                test : /\.js$/, use : {
                loader : 'babel-loader',
                options : {
                    presets : ['es2015']
                }
            }}
        ]
    }
};

app.js file

import './a.js';

function helloworld()
{
    console.log(1);
}

When only webpack is used, js files can be generated and executed by babel-loader, but when gulp is executed, babel-loader is not executed.
Beginner to webpack and gulp~Thank you for your advice~~

仅有的幸福仅有的幸福2752 days ago667

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-19 10:38:28

    Because webpack in webpack-stream is still 1.9.0, the webpackconfig you use already has 2.0 syntax, similar to rules.

    It makes sense not to execute it. If you want to use gulp+webpack, you can refer to webpack-stream

    If you would like to use a different version of webpack than the one this plugin uses, pass in an optional 2nd argument:

    var gulp = require('gulp');
    var webpack2 = require('webpack2');
    var gulpWebpack = require('webpack-stream');
    gulp.task('default', function() {
      return gulp.src('src/entry.js')
        .pipe(gulpWebpack({}, webpack))
        .pipe(gulp.dest('dist/'));
    });

    By the way, let me give you an answer to a question that others have asked.
    http://stackoverflow.com/ques...

    reply
    0
  • Cancelreply