Skip to content

Commit 6bdecc6

Browse files
authored
fix: keep css code on web, and dont always recreate uniwind files (#101)
1 parent f00ca2e commit 6bdecc6

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

packages/uniwind/src/css/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ export const buildCSS = (themes: Array<string>, input: string) => {
99
const insets = generateCSSForInsets()
1010
const themesCSS = generateCSSForThemes(themes, input)
1111
const cssFile = path.join(__dirname, '../../uniwind.css')
12+
const oldCSSFile = fs.existsSync(cssFile)
13+
? fs.readFileSync(cssFile, 'utf-8')
14+
: ''
15+
16+
if (oldCSSFile === cssFile) {
17+
return
18+
}
1219

1320
fs.writeFileSync(
1421
cssFile,

packages/uniwind/src/metro/injectThemes.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,42 @@ type InjectThemesConfig = {
88
input: string
99
}
1010

11+
const buildDtsFile = (dtsPath: string, stringifiedThemes: string) => {
12+
const oldDtsContent = fs.existsSync(dtsPath)
13+
? fs.readFileSync(dtsPath, 'utf-8')
14+
: ''
15+
const dtsContent = [
16+
`// NOTE: This file is generated by ${name} and it should not be edited manually.`,
17+
`/// <reference types="${name}/types" />`,
18+
'',
19+
`declare module '${name}' {`,
20+
` export interface UniwindConfig {`,
21+
` themes: readonly ${stringifiedThemes}`,
22+
` }`,
23+
`}`,
24+
'',
25+
`export {}`,
26+
'',
27+
].join('\n')
28+
29+
if (oldDtsContent === dtsContent) {
30+
return
31+
}
32+
33+
fs.writeFileSync(
34+
dtsPath,
35+
dtsContent,
36+
)
37+
}
38+
1139
export const injectThemes = ({
1240
themes,
1341
dtsPath = 'uniwind-types.d.ts',
1442
input,
1543
}: InjectThemesConfig) => {
1644
const stringifiedThemes = `[${themes.map(theme => `'${theme}'`).join(', ')}]`
1745

18-
// d.ts generation
19-
fs.writeFileSync(
20-
dtsPath,
21-
[
22-
`// NOTE: This file is generated by ${name} and it should not be edited manually.`,
23-
`/// <reference types="${name}/types" />`,
24-
'',
25-
`declare module '${name}' {`,
26-
` export interface UniwindConfig {`,
27-
` themes: readonly ${stringifiedThemes}`,
28-
` }`,
29-
`}`,
30-
'',
31-
`export {}`,
32-
'',
33-
].join('\n'),
34-
)
46+
buildDtsFile(dtsPath, stringifiedThemes)
3547
buildCSS(themes, input)
3648

3749
// js generation

packages/uniwind/src/metro/metro-transformer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ export const transform = async (
9999
)
100100

101101
uniwindCache.cachedTransforms.set(platform, transform)
102-
transform.output[0].data.css = {
103-
skipCache: true,
104-
code: '',
102+
transform.output[0].data.css.skipCache = true
103+
104+
if (!isWeb) {
105+
transform.output[0].data.css.code = ''
105106
}
106107

107108
return transform

0 commit comments

Comments
 (0)