Webpack-stream:如何使用配置数组?

时间:2017-03-19 14:26:12

标签: webpack webpack-2

如果我通过CLI使用webpack,我可以导出配置数组:

module.exports = [
  {
    entry: {/*entry#1*/},
    target: 'electron-renderer'
    //...
  },
  {
    entry: {/*entry#2*/}
    target: 'webworker'
    //...
  }
];

它工作正常。但是当我尝试通过webpack-stream中的gulpfile.js传递它时

const webpackStream = require('webpack-stream');
const webpack2 = require('webpack');
const webpackConf = require('./webpack.config.js');

...

gulp.task('run webpack', () => {
  return gulp.src('src/app.js') // I use only entry#1 here, cause it should override it via config file... I suppose
    .pipe(webpackStream(webpackConf, webpack2))
    .pipe(gulp.dest('dest/app'));
});

它完成任务没有错误,但从不将结果文件插入输出文件夹。

如果我写webpackStream(webpackConf[0], webpack2)webpackStream(webpackConf[1], webpack2)(只有我的一个配置),它的效果会很好。

1 个答案:

答案 0 :(得分:0)

您要找的是webpack-stream的{​​{3}}。

您甚至不需要gulp.src来自您的webpack配置的第一个条目,并且可以执行以下操作:

const webpackStream = require('webpack-stream');
const webpack2 = require('webpack');
const webpackConf = require('./webpack.config.js');

gulp.task('run webpack', () => {
  return webpackStream({config: webpackConf}, webpack2)
    .pipe(gulp.dest('dest/app'));
});