From c1f7c8695ff6385068ca55f14b4d36fdd973c65d Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Fri, 29 Mar 2019 17:51:36 -0400 Subject: [PATCH] feat(ordering): add support for insertInto option This adds an new `insertInto` option that is optional and backards-compatible. Specifying a CSS selector allows the user to specify a DOM node into which the async-loaded tags should be inserted. Closes #370, related to #328,#331 --- src/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index c905bb825..3ce9a3b56 100644 --- a/src/index.js +++ b/src/index.js @@ -113,6 +113,7 @@ class MiniCssExtractPlugin { this.options = Object.assign( { filename: '[name].css', + insertInto: null, }, options ); @@ -378,8 +379,10 @@ class MiniCssExtractPlugin { '}', ]) : '', - 'var head = document.getElementsByTagName("head")[0];', - 'head.appendChild(linkTag);', + `var selector = "${this.options.insertInto}";`, + 'var parent = selector && document.querySelector && document.querySelector(selector);', + 'if (parent) { parent.appendChild(linkTag); }', + 'else { document.getElementsByTagName("head")[0].appendChild(linkTag); }', ]), '}).then(function() {', Template.indent(['installedCssChunks[chunkId] = 0;']),