feat: custom css import

This commit is contained in:
Mark Lawlor
2022-10-10 00:23:45 +10:00
parent 300a0f9cf2
commit 6b809485de
3 changed files with 28 additions and 6 deletions

4
package-lock.json generated
View File

@@ -35968,11 +35968,12 @@
}
},
"packages/nativewind": {
"version": "3.0.0-next.1-3-g91e5901",
"version": "3.0.0-next.1-10-g0123a38",
"license": "MIT",
"dependencies": {
"@babel/helper-module-imports": "7.18.6",
"@babel/types": "7.19.0",
"@expo/config": "^7.0.1",
"css-tree": "^2.2.1",
"find-cache-dir": "^3.3.2",
"micromatch": "^4.0.5",
@@ -56127,6 +56128,7 @@
"@babel/helper-module-imports": "7.18.6",
"@babel/plugin-syntax-jsx": "7.18.6",
"@babel/types": "7.19.0",
"@expo/config": "*",
"@testing-library/react-hooks": "8.0.1",
"@testing-library/react-native": "11.1.0",
"@types/css-tree": "^1.0.7",

View File

@@ -51,6 +51,7 @@
"dependencies": {
"@babel/helper-module-imports": "7.18.6",
"@babel/types": "7.19.0",
"@expo/config": "^7.0.1",
"css-tree": "^2.2.1",
"find-cache-dir": "^3.3.2",
"micromatch": "^4.0.5",

View File

@@ -1,8 +1,11 @@
import { writeFileSync } from "node:fs";
/* eslint-disable unicorn/prefer-module, @typescript-eslint/no-var-requires */
import { readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import findCacheDir from "find-cache-dir";
import { spawn, spawnSync } from "node:child_process";
import { resolveEntryPoint } from "@expo/config/paths";
import findCacheDir from "find-cache-dir";
import { getCreateOptions } from "../postcss/extract";
export interface WithNativeWindOptions {
@@ -23,8 +26,24 @@ export default function withNativeWind(
process.env.NATIVEWIND_OUTPUT = outputFile;
if (!inputPath) {
inputPath = join(cacheDirectory, "input.css");
writeFileSync(inputPath, "@tailwind components;@tailwind utilities;");
try {
let { main } = require("package.json");
if (main && main === "node_modules/expo/AppEntry.js") {
main = resolveEntryPoint(__dirname, { platform: "ios" });
}
if (main) {
const cssImport = readFileSync(main, "utf8").match(/(\w+\.css)/);
if (cssImport) {
inputPath = cssImport[0];
}
}
} finally {
inputPath ??= join(cacheDirectory, "input.css");
writeFileSync(inputPath, "@tailwind components;@tailwind utilities;");
}
}
const spawnCommands = ["tailwind", "-i", inputPath];