Skip to content

Commit

Permalink
fix: Webpack style loader.
Browse files Browse the repository at this point in the history
Webpack style loader's insert option needs a different way to reference functions.
Also deprecate webpack-helpers module.
  • Loading branch information
thet committed Aug 14, 2024
1 parent 9164405 commit ecec3cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
12 changes: 12 additions & 0 deletions webpack/style-inserter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function style_inserter(el) {
// Insert element at the top of <head>
// Used for injecting CSS via webpack before any other CSS
var first_child = document.head.querySelectorAll("*")[0];
if (first_child) {
document.head.insertBefore(el, first_child);
} else {
document.head.append(el);
}
}

module.exports = style_inserter;
17 changes: 4 additions & 13 deletions webpack/webpack-helpers.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
function top_head_insert(el) {
// Insert element at the top of <head>
// Used for injecting CSS via webpack before any other CSS
// Note:
// Keep code compatible with IE11 as long as we support it.
var first_child = document.head.querySelectorAll("*")[0];
if (first_child) {
document.head.insertBefore(el, first_child);
} else {
document.head.append(el);
}
}
// BBB
// TODO: Remove in next major version.
const style_inserter = require("./style-inserter");

module.exports = {
top_head_insert: top_head_insert,
top_head_insert: style_inserter,
};
3 changes: 1 addition & 2 deletions webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
process.traceDeprecation = true;
const webpack = require("webpack");
const webpack_helpers = require("./webpack-helpers");

// plugins
const TerserPlugin = require("terser-webpack-plugin");
Expand Down Expand Up @@ -60,7 +59,7 @@ const config_factory = (env, argv, config, babel_include = [], package_json) =>
{
loader: "style-loader",
options: {
insert: webpack_helpers.top_head_insert,
insert: require.resolve("./style-inserter"),
},
},
"css-loader",
Expand Down

0 comments on commit ecec3cf

Please sign in to comment.