-
Notifications
You must be signed in to change notification settings - Fork 3
/
theme.config.js
48 lines (45 loc) Β· 1.12 KB
/
theme.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const less = require('less')
const { getLessOptions } = require('less-loader/dist/utils')
const { getThemeVariables } = require('ant-design-vue/dist/theme')
const themeConfig = [
{
theme: 'dark',
htmlThemeAttr: 'dark',
modifyVars: { ...getThemeVariables({ dark: true }), 'text-color': 'fade(@white, 65%)' }
}
]
async function additionalData (content, loaderContext) {
const themePromises = themeConfig.map(async t => {
const { htmlThemeAttr, modifyVars = {} } = t
const options = getLessOptions(loaderContext, {
lessOptions: {
javascriptEnabled: true,
modifyVars
}
})
try {
const { css } = await less.render(content, options)
let res = ''
if (htmlThemeAttr && css) {
res = `
[theme=${htmlThemeAttr}] {
${css}
}
`
}
return Promise.resolve(res)
} catch (error) {
return Promise.reject(content)
}
})
let res = content
for (const themePromise of themePromises) {
const theme = await themePromise
res += theme
}
return res
}
module.exports = {
themeConfig,
additionalData
}