codymikol / karma-webpack

Karma webpack Middleware
MIT License
830 stars 221 forks source link

Merging does not work, plugins get duplicated #496

Closed lk77 closed 3 years ago

lk77 commented 3 years ago

Expected Behavior

Plugins are only included once

Actual Behavior

Plugins are included twice due to issue when merging webpack config

Code

webpack config :

 plugins: [
        new VueLoaderPlugin()
    ],

webpack config after merging (this.webpackOptions)

 plugins: [
    VueLoaderPlugin {},
    VueLoaderPlugin {},
    KW_WebpackPlugin {
      karmaEmitter: [Server],
      controller: [KW_Controller]
    }
  ],

How Do We Reproduce?

Add a plugin in your webpack config and see that this plugin is added twice

thanks

codymikol commented 3 years ago

Was this not an issue?

lk77 commented 3 years ago

no it was not, an issue on my end

i have done that to enforce my webpack config :

const webpackConfig = require('./webpack.config.test.js')
let DefaultWebpackOptionsFactory = require('karma-webpack/lib/webpack/defaults');

DefaultWebpackOptionsFactory.create = () => {
    return webpackConfig;
};

require.cache[require.resolve('karma-webpack/lib/webpack/defaults')].exports = DefaultWebpackOptionsFactory;

it's a little dirty but it's the only way i found to make my webpack config works (multiple entry with multiple outputs)

but i needed to change the karma config

webpack: {}

if not when merging plugins, they were included twice