You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This approach should be sufficient unless you are using custom injection code to insert styles where needed.
83
-
Since the dev environment involve the concept of "update" the style in the DOM this plugin need at least the code that remove from the DOM the injected style.
84
-
Because of all of this, **if you are using custom injection code (by using `injectCode` or `injectCodeFunction`)**, this plugin can't know how to delete the style you injected.
85
-
So all you need to do is configure one of `removeStyleCode`, `removeStyleCodeFunction` inside the dev object showed above.
86
89
87
-
**NOTE:** The `injectCode` and `injectCodeFunction` parameters now also include the `attributes`, and in dev mode, the attributes object encompasses the `data-vite-dev-id` as well. Refer to the `injectCodeFunction` example below for further details.
90
+
This approach should serve its purpose effectively unless you're employing custom injection code to insert styles where
91
+
necessary. Since the development environment involves the concept of "updating" styles in the Document Object Model (
92
+
DOM), this plugin requires code to remove the injected style from the DOM.
93
+
94
+
Due to these factors, if you're utilizing custom injection code (via `injectCode` or `injectCodeFunction`), the plugin
95
+
cannot automatically discern how to delete the injected style. Therefore, all you need to do is configure
96
+
either `removeStyleCode` or `removeStyleCodeFunction` within the `dev` object as demonstrated above.
97
+
98
+
**NOTE:** The `injectCode` and `injectCodeFunction` parameters now also include the `attributes`, and in `dev` mode,
99
+
the `attributes` object encompasses the `data-vite-dev-id` as well. Refer to the `injectCodeFunction` example below for
100
+
further details.
88
101
89
102
#### injectCode (function)
90
103
91
-
You can provide also a function for `injectCode` param to customize the injection code used.
92
-
The `injectCode` callback must return a `string` (with valid JS code) and it's called with two arguments:
104
+
You can provide also a function for `injectCode` param to customize the injection code used. The `injectCode` callback
105
+
must return a `string` (with valid JS code) and it's called with two arguments:
93
106
94
107
- cssCode (the `string` that contains all the css code that need to be injected via JavaScript)
95
-
- options (an object with `styleId`, `useStrictCSP` and `attributes` the last is an object that represent the attributes of the style element that should have)
108
+
- options (an object with `styleId`, `useStrictCSP` and `attributes` the last is an object that represent the attributes
@@ -116,7 +131,8 @@ If you prefer to specify the injectCode as a plain function you can use the `inj
116
131
The `injectCodeFunction` function is a void function that will be called at runtime application with two arguments:
117
132
118
133
- cssCode (the `string` that contains all the css code that need to be injected via JavaScript)
119
-
- options (an object with `styleId`, `useStrictCSP` and `attributes` the last is an object that represent the attributes of the style element that should have)
134
+
- options (an object with `styleId`, `useStrictCSP` and `attributes` the last is an object that represent the attributes
_This feature is based on information provided by Vite. Since we can't control how Vite handles this information this means that there may be problems that may not be possible to fix them in this plugin._
233
+
_This feature is based on information provided by Vite. Since we can't control how Vite handles this information this
234
+
means that there may be problems that may not be possible to fix them in this plugin._
218
235
219
236
The default behavior of this plugin takes all the CSS code of your application directly to the entrypoint generated.
220
-
The `relativeCSSInjection` if configured to `true` will inject the CSS code of every entrypoint to the relative importer.
237
+
The `relativeCSSInjection` if configured to `true` will inject the CSS code of every entrypoint to the relative
238
+
importer.
221
239
222
240
**Set this option to `true` if you are using the multiple entry point option of Rollup.**
223
241
**For this feature to work, `build.cssCodeSplit` must be set to `true`**
224
242
225
-
_Future release can have an advanced behavior where this options will be configured to true automatically by sniffing user configurations._
243
+
_Future release can have an advanced behavior where this options will be configured to true automatically by sniffing
244
+
user configurations._
226
245
227
-
If a CSS chunk is generated that's not imported by any JS chunk, a warning will be shown.
228
-
To disable this warning set `suppressUnusedCssWarning` to `true`.
246
+
If a CSS chunk is generated that's not imported by any JS chunk, a warning will be shown. To disable this warning
247
+
set `suppressUnusedCssWarning` to `true`.
229
248
230
249
#### styleId (string | function)
231
250
@@ -251,7 +270,8 @@ The output injected into the DOM will look like this example:
251
270
</head>
252
271
```
253
272
254
-
If you provide a `function` for `styleId` param, it will run that function and return a string. It's especially useful if you use `relativeCSSInjection` and want unique styleIds for each file.
273
+
If you provide a `function` for `styleId` param, it will run that function and return a string. It's especially useful
274
+
if you use `relativeCSSInjection` and want unique styleIds for each file.
@@ -309,7 +330,7 @@ will be injected by our default injection code.
309
330
310
331
## Contributing
311
332
312
-
When you make changes to plugin locally, you may want to build the js from the typescript file of the plugin.
333
+
When you make changes to plugin locally, you may want to build the js from the typescript file of the plugin.
313
334
314
335
Here the guidelines:
315
336
@@ -333,7 +354,9 @@ npm run build
333
354
334
355
See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
335
356
336
-
337
357
### A note for plugin-legacy users
338
-
At first the plugin supported generating the CSS injection code also in the legacy files generated by the [plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy). Since the plugin-legacy injects the CSS code for [different reasons](https://github.com/vitejs/vite/issues/2062), this plugin no longer has the plugin-legacy support code.
339
-
If the code of the plugin-legacy changes an update to this plugin may occur.
358
+
359
+
At first the plugin supported generating the CSS injection code also in the legacy files generated by
360
+
the [plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy). Since the plugin-legacy injects
361
+
the CSS code for [different reasons](https://github.com/vitejs/vite/issues/2062), this plugin no longer has the
362
+
plugin-legacy support code. If the code of the plugin-legacy changes an update to this plugin may occur.
0 commit comments