codymikol / karma-webpack

Karma webpack Middleware
MIT License
829 stars 222 forks source link

fix(config): force default output.filename #477

Closed codymikol closed 3 years ago

codymikol commented 3 years ago

This PR contains a:

Motivation / Use-Case

this prevents karma-webpack from failing and also prints out a useful error message explaining why the webpack output.filename is ignored.

Fixes N/A

Breaking Changes

N/A

Additional Info

N/A

lk77 commented 3 years ago

Hello,

why this change ?

it was previously working fine.

karma-webpack does not currently support customized filenames via
webpack output.filename, if this is something you need consider opening an issue.
defaulting apps/[name]/assets/js/[name].bundle.js to [name].js

every output file is in the root directory now, and not in their own directories, and they are all called 'index.js', and webpack seems to add a random number to it :

/index.1721931596.js: "7897ba0a8043ef409538a45a9ecf566c56d8e54a"
/index.2115725147.js: "5a9c9117f70b83c0f6d05445cc7fefd8bb869012"
/index.2611944535.js: "afb25cd9c4d6094784849673f10664f94462f651"
/index.2882415412.js: "b39c38b5c51036253554d18f9d21f24d0bfc366f"
/index.3427415320.js: "9992e0308c5c29b2ad1cf4706421023216e86aec"
/index.1491000527.js: "4b9763bd2973df908ee137f6f041a114af910549"
/index.1674761228.js: "98899a48d8283411f35b2e3f785c0391f6e76da6"

and it generate two files commons.js and runtime.js that should not be there.

i think karma-webpack should strictly respect the webpack.config.js file.

edit :

for now this seems to work :

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;

my webpack config is overriding the config provided by karma-webpack and i could get rid of commons.js/runtime.js and having my build files.