-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathinjection-code.ts
More file actions
34 lines (30 loc) · 1.15 KB
/
injection-code.ts
File metadata and controls
34 lines (30 loc) · 1.15 KB
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
/**
* This is a hack around Metro's handling of bundles.
* When a component is inside a lazy() barrier, it is inside a different JS bundle.
* So when it updates, it only updates its local bundle, not the global one which contains the CSS files.
*
* This means that the CSS file will not be re-evaluated when a component in a different bundle updates,
* breaking tools like Tailwind CSS
*
* To fix this, we force our code to always import the CSS files, so now the CSS files are in every bundle.
*/
export function getWebInjectionCode(filePaths: string[]) {
const importStatements = filePaths
.map((filePath) => `import "${filePath}";`)
.join("\n");
return Buffer.from(importStatements);
}
export function getNativeInjectionCode(
cssFilePaths: string[],
values: unknown[],
) {
const importStatements = cssFilePaths
.map((filePath) => `import "${filePath}";`)
.join("\n");
const contents = values
.map((value) => `StyleCollection.inject(${JSON.stringify(value)});`)
.join("\n");
return Buffer.from(
`import { StyleCollection } from "react-native-css/native-internal";\n${importStatements}\n${contents};export {};`,
);
}