Skip to content

Commit 5ca36b0

Browse files
committed
changed to allow for attributes to be provided to the <style> tag
1 parent 8cd4ad9 commit 5ca36b0

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/core/base-plugin.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,26 @@ export class BasePlugin {
7575
htmlFileName: string
7676
style: string
7777
}) {
78-
const styleString = this.config.noStyleTag
79-
? style
80-
: `<style type="text/css">${style}</style>`
78+
let attributesString = ''
79+
80+
if (this.config.attributes) {
81+
if (
82+
typeof this.config.attributes !== 'object' &&
83+
this.config.attributes === null
84+
) {
85+
throw new Error(
86+
`Please provide a key/value object if intending to use the attributes option`,
87+
)
88+
}
89+
90+
Object.keys(this.config.attributes).map((key) => {
91+
const value = this.config.attributes[key] || ''
92+
attributesString += ` ${key}="${value}"`
93+
})
94+
}
95+
96+
const styleString = `<style${attributesString}>${style}</style>`
97+
8198
const replaceValues = [styleString, this.replaceConfig.target]
8299

83100
if (this.replaceConfig.position === 'after') {

src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface Config {
1414
filter?(fileName: string): boolean
1515
leaveCSSFile?: boolean
1616
replace?: ReplaceConfig
17-
noStyleTag?: boolean
17+
attributes?: any
1818
}
1919

2020
export interface FileCache {

0 commit comments

Comments
 (0)