2015-06-30 31 views
1

我試圖讓webpack用不同的插件集合收集兩個文件。 我想像是這樣的:針對不同入口點的各種插件

{ 
    entry: { 
     name: "./first", 
     output: { 
      path: path.join(__dirname, "js"), 
      filename: "first.js" 
     }, 
     plugins: [ 
      new FirstPlugin() 
     ], 
    }, 
    entry: { 
     name: "./second", 
      path: path.join(__dirname, "js"), 
      filename: "second.js" 
     }, 
     plugins: [ 
      new AnotherPlugin() 
     ] 
    } 
} 

但它肯定是行不通的。 是否有可能獲得當前entripoint進入插件運行時?然後,一切都將決定一個IF。

回答

0

如果您在兩個不同的入口點和輸出上運行,那麼您可以簡單地運行兩個不同的webpack進程,例如(簡化)。

//webpack.config.js 
module.exports = [ 
{ 
    name: 'first', 
    entry: { 
     main: "./first" 
    } 
    output: { 
     path: path.join(__dirname, "js"), 
      filename: "first.js" 
    }, 
    plugins: [ 
      new FirstPlugin() 
     ] 
    } 
}, 
{ 
    name: 'second', 
    entry: { 
     main: "./second" 
    } 
    output: { 
     path: path.join(__dirname, "js"), 
      filename: "second.js" 
    }, 
    plugins: [ 
      new SecondPlugin() 
     ] 
    } 
} 
];