diff --git a/packages/browser-tailwind/src/index.ts b/packages/browser-tailwind/src/index.ts index 0a1cf86..6fb35f2 100644 --- a/packages/browser-tailwind/src/index.ts +++ b/packages/browser-tailwind/src/index.ts @@ -1,7 +1,8 @@ import postcss from "postcss"; import tailwindcss, { Config } from "tailwindcss"; import { - VIRTUAL_HTML_FILENAME, + VIRTUAL_CONTENT_EXTNAME, + VIRTUAL_CONTENT_FILENAME, VIRTUAL_SOURCE_PATH, } from "./polyfill/constants"; @@ -12,14 +13,16 @@ self.process = { export async function compileTailwindCSS( cssInput: string, - htmlInput: string, + contentInput: string, + extname: string, config: Config | {} = {}, plugins = [], ) { + self[VIRTUAL_CONTENT_EXTNAME] = extname; // Tailwind scans the config.content for files to parse classNames -> set a virtual file here - if ("content" in config) { - self[VIRTUAL_HTML_FILENAME] = htmlInput; - config.content = [VIRTUAL_HTML_FILENAME]; + if (!("content" in config)) { + self[VIRTUAL_CONTENT_FILENAME] = contentInput; + (config as Config).content = [VIRTUAL_CONTENT_FILENAME]; } return await postcss([ tailwindcss(config as Config), diff --git a/packages/browser-tailwind/src/polyfill/constants.ts b/packages/browser-tailwind/src/polyfill/constants.ts index 53985bd..8dc652b 100644 --- a/packages/browser-tailwind/src/polyfill/constants.ts +++ b/packages/browser-tailwind/src/polyfill/constants.ts @@ -2,5 +2,6 @@ /** * Dummy constant for Node like environment in Browser for lib depending on fs module, like PostCSS */ -export const VIRTUAL_SOURCE_PATH = "/sourcePath"; -export const VIRTUAL_HTML_FILENAME = "/htmlInput"; +export const VIRTUAL_SOURCE_PATH = "BROWSER_TAILWIND_VIRTUAL_SOURCE_PATH"; +export const VIRTUAL_CONTENT_FILENAME = "BROWSER_TAILWIND_VIRTUAL_CONTENT_FILENAME"; +export const VIRTUAL_CONTENT_EXTNAME = "BROWSER_TAILWIND_VIRTUAL_CONTENT_EXTNAME"; diff --git a/packages/browser-tailwind/src/polyfill/fs.ts b/packages/browser-tailwind/src/polyfill/fs.ts index bbf2fde..77e7756 100644 --- a/packages/browser-tailwind/src/polyfill/fs.ts +++ b/packages/browser-tailwind/src/polyfill/fs.ts @@ -11,5 +11,10 @@ export default { } return { mtimeMs: ++i }; }, - readFileSync: (id) => self[id] || "", + readFileSync: (id) => self[id] ?? "", + promises: { + readFile(id) { + return self[id] ?? ""; + }, + }, }; diff --git a/packages/browser-tailwind/src/polyfill/path.ts b/packages/browser-tailwind/src/polyfill/path.ts index 93bc746..111fe41 100644 --- a/packages/browser-tailwind/src/polyfill/path.ts +++ b/packages/browser-tailwind/src/polyfill/path.ts @@ -1,9 +1,13 @@ //@ts-nocheck +import { VIRTUAL_CONTENT_EXTNAME } from "./constants"; + self.__dirname = ""; export default { join: () => { return ""; }, + resolve: (id) => id, + extname: (id) => self[VIRTUAL_CONTENT_EXTNAME], }; export const join = () => {