From 7122cdec2d2e69f70bf6a0edeab91e2661444b95 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Mon, 8 Apr 2024 19:11:59 +0300 Subject: [PATCH] refactor!: the `insert` option can only be a `selector` or the path to the module --- README.md | 181 ++++++++++-------- src/index.js | 8 +- src/options.json | 18 +- src/utils.js | 33 ++-- .../validate-options.test.js.snap | 24 +-- test/fixtures/insert-options.js | 5 + test/fixtures/insert-test-shadow.js | 6 + test/fixtures/insert-to-existing-style.js | 20 ++ test/fixtures/insert-top.js | 19 ++ test/insert-option.test.js | 41 +--- test/lazyStyleTag-options.test.js | 8 +- test/validate-options.test.js | 2 +- 12 files changed, 180 insertions(+), 185 deletions(-) create mode 100644 test/fixtures/insert-options.js create mode 100644 test/fixtures/insert-test-shadow.js create mode 100644 test/fixtures/insert-to-existing-style.js create mode 100644 test/fixtures/insert-top.js diff --git a/README.md b/README.md index 79fb2999..0ddd5580 100644 --- a/README.md +++ b/README.md @@ -450,9 +450,7 @@ module.exports = { Type: ```ts -type insert = - | string - | ((htmlElement: HTMLElement, options: Record) => void); +type insert = string; ``` Default: `head` @@ -462,9 +460,7 @@ This will cause CSS created by the loader to take priority over CSS already pres You can use other values if the standard behavior is not suitable for you, but we do not recommend doing this. If you target an [iframe](https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement) make sure you have sufficient access rights, the styles will be injected into the content document head. -#### `string` - -##### `Selector` +#### `Selector` Allows to setup custom [query selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) where styles inject into the DOM. @@ -491,7 +487,7 @@ module.exports = { }; ``` -##### `Absolute path to function` +#### `Absolute path to function` Allows to setup absolute path to custom function that allows to override default behavior and insert styles at any position. @@ -515,7 +511,7 @@ module.exports = { { loader: "style-loader", options: { - insert: require.resolve("modulePath"), + insert: require.resolve("./path-to-insert-module"), }, }, "css-loader", @@ -528,17 +524,32 @@ module.exports = { A new `