搜尋

首頁  >  問答  >  主體

javascript - gulp執行webpack任務時, 檔案產生, loader沒被執行.

gulpfile.js 設定檔

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 設定檔

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

app.js 檔案

import './a.js';

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

只有webpack時, js檔案是可以產生且能被babel-loader執行, 但執行gulp時, babel-loader便沒執行了.
初學webpack與gulp ~ 感謝各位指教~~

仅有的幸福仅有的幸福2804 天前698

全部回覆(1)我來回復

  • 巴扎黑

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

    因為webpack-stream裡面的webpack還是1.9.0,你用的webpackconfig已經是2.0的文法,類似rules那些。

    不執行是有道理的,想用gulp+webpack的話,可以參考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/'));
    });

    順便給一個別人問過的問題的答案。
    http://stackoverflow.com/ques...

    回覆
    0
  • 取消回覆