From 67120f8dc831626f466d64513b4e26074e89341b Mon Sep 17 00:00:00 2001 From: Ian Will Date: Fri, 8 Sep 2017 19:56:21 -0400 Subject: [PATCH] feat: support 'before' insertions (`options.insertAt`) (#253) --- README.md | 16 +++++++++++++++- lib/addStyles.js | 5 ++++- options.json | 2 +- test/basicTest.js | 22 +++++++++++++++++++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d0fcbb71..ad81b4e9 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Styles are not added on `import/require()`, but instead on call to `use`/`ref`. |**`base`** |`{Number}`|`true`|Set module ID base (DLLPlugin)| |**`attrs`**|`{Object}`|`{}`|Add custom attrs to ``| |**`transform`** |`{Function}`|`false`|Transform/Conditionally load CSS by passing a transform/condition function| -|**`insertAt`**|`{String}`|`bottom`|Inserts `` at the given position| +|**`insertAt`**|`{String\|Object}`|`bottom`|Inserts `` at the given position| |**`insertInto`**|`{String}`|``|Inserts `` into the given position| |**`sourceMap`**|`{Boolean}`|`false`|Enable/Disable Sourcemaps| |**`convertToAbsoluteUrls`**|`{Boolean}`|`false`|Converts relative URLs to absolute urls, when source maps are enabled| @@ -285,6 +285,20 @@ By default, the style-loader appends ``, - existingStyle = "", + existingStyle = ``, checkValue = '
check
', rootDir = path.resolve(__dirname + "/../") + "/", jsdomHtml = [ @@ -95,6 +95,26 @@ describe("basic tests", function() { runCompilerTest(expected, done); }); // it insert at top + it("insert at before", function(done) { + styleLoaderOptions.insertAt = { + before: "#existing-style" + }; + + let expected = [requiredStyle, existingStyle].join(""); + + runCompilerTest(expected, done); + }); // it insert at before + + it("insert at before invalid selector", function(done) { + styleLoaderOptions.insertAt = { + before: "#missing" + }; + + let expected = [existingStyle, requiredStyle].join("\n"); + + runCompilerTest(expected, done); + }); // it insert at before + it("insert into", function(done) { let selector = "div.target"; styleLoaderOptions.insertInto = selector;