File tree 3 files changed +43
-7
lines changed
3 files changed +43
-7
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,8 @@ module.exports = {
53
53
## Config
54
54
``` typescript
55
55
interface Config {
56
- filter? (fileName : string ): boolean
56
+ filter? : (fileName : string ) => boolean
57
+ styleTagFactory? : (params : { style: string }) => string
57
58
leaveCSSFile? : boolean
58
59
replace? : {
59
60
target: string
@@ -65,15 +66,33 @@ interface Config {
65
66
66
67
### filter(optional)
67
68
``` typescript
68
- filter ? (fileName : string ): boolean
69
+ filter ?: (fileName : string ) => boolean
69
70
```
70
71
Return ` true ` to make current file internal, otherwise ignore current file. Include both css file and html file name.
72
+ ##### example
73
+ ``` typescript
74
+ ...
75
+ new HTMLInlineCSSWebpackPlugin ({
76
+ filter(fileName ) {
77
+ return fileName .includes (' main' );
78
+ },
79
+ }),
80
+ ...
81
+ ```
82
+
83
+ ### styleTagFactory(optional)
84
+ ``` typescript
85
+ styleTagFactory ?: (params : { style: string }) => string
86
+ ```
87
+
88
+ Used to customize the style tag.
89
+
71
90
##### example
72
91
``` typescript
73
92
...
74
93
new HTMLInlineCSSWebpackPlugin ({
75
- filter( fileName ) {
76
- return fileName . includes ( ' main ' ) ;
94
+ styleTagFactory({ style } ) {
95
+ return ` <style type="text/css">${ style }</style> ` ;
77
96
},
78
97
}),
79
98
...
Original file line number Diff line number Diff line change 1
- import { Config , DEFAULT_REPLACE_CONFIG , FileCache } from '../types'
1
+ import {
2
+ Config ,
3
+ StyleTagFactory ,
4
+ DEFAULT_REPLACE_CONFIG ,
5
+ FileCache ,
6
+ } from '../types'
2
7
import { isCSS , escapeRegExp } from '../utils'
3
8
4
9
interface Asset {
@@ -17,6 +22,13 @@ export class BasePlugin {
17
22
return this . config . replace || DEFAULT_REPLACE_CONFIG
18
23
}
19
24
25
+ protected get styleTagFactory ( ) : StyleTagFactory {
26
+ return (
27
+ this . config . styleTagFactory ||
28
+ ( ( { style } ) => `<style type="text/css">${ style } </style>` )
29
+ )
30
+ }
31
+
20
32
constructor ( protected readonly config : Config = { } ) { }
21
33
22
34
protected prepare ( { assets } : Compilation ) {
@@ -75,8 +87,10 @@ export class BasePlugin {
75
87
htmlFileName : string
76
88
style : string
77
89
} ) {
78
- const styleString = `<style type="text/css">${ style } </style>`
79
- const replaceValues = [ styleString , this . replaceConfig . target ]
90
+ const replaceValues = [
91
+ this . styleTagFactory ( { style } ) ,
92
+ this . replaceConfig . target ,
93
+ ]
80
94
81
95
if ( this . replaceConfig . position === 'after' ) {
82
96
replaceValues . reverse ( )
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ export interface ReplaceConfig {
4
4
target : string
5
5
}
6
6
7
+ export type StyleTagFactory = ( params : { style : string } ) => string
8
+
7
9
export const TAP_KEY_PREFIX = 'html-inline-css-webpack-plugin'
8
10
9
11
export const DEFAULT_REPLACE_CONFIG : ReplaceConfig = {
@@ -14,6 +16,7 @@ export interface Config {
14
16
filter ?( fileName : string ) : boolean
15
17
leaveCSSFile ?: boolean
16
18
replace ?: ReplaceConfig
19
+ styleTagFactory ?: StyleTagFactory
17
20
}
18
21
19
22
export interface FileCache {
You can’t perform that action at this time.
0 commit comments