I am working on a legacy project (based on jQuery). Some CSS is added with Javascript by simply appending the style-tag to the header:
$("head").append("<link href='" + path + "' rel='stylesheet' type='text/css' media='screen' />")
I cannot rewrite the code using CSS modules so I am wondering if there is a way to bundle this CSS that gets injected via Javascript using Webpack 5.
Found a way to make it work using require.context.
The following line makes all js files inside a certain folder available as build dependencies:
And this actually uses them (the jQuery code is just there because this legacy project is using jQuery, the important part is
req_js(key)):More interesting background info regarding require.context here: What is `require.context`?