Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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