diff --git a/scripts/index.ts b/scripts/index.ts index ee8c12f..a48ccbe 100755 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -1,5 +1,6 @@ #!/usr/bin/env bun import { type Options, build } from "tsup"; +import { promises as fs } from "node:fs"; import tsupConfig from "../tsup.config"; import { pick } from "lodash"; import pkg from "../package.json" with { type: "json" }; @@ -18,4 +19,7 @@ await Bun.write( `dist/base.d.ts`, `/**\n * \`@tailwind base\` component.\n */\nexport {};` ); +await fs.copyFile("README.md", "dist/README.md"); +await fs.copyFile("LICENSE.md", "dist/LICENSE.md"); + process.exit(0); diff --git a/src/index.ts b/src/index.ts index d25bb86..3f50a99 100644 --- a/src/index.ts +++ b/src/index.ts @@ -332,12 +332,12 @@ const esbuildPlugin = ( }); build.onResolve({ filter: RegExp(`^${name}/base$`) }, () => ({ - path: "directive:babel", + path: "directive:base", namespace: ESBUILD_NAMESPACE, })); build.onLoad({ filter: /.*/, namespace: ESBUILD_NAMESPACE }, async ({ path }) => { - if (path === "directive:babel") { + if (path === "directive:base") { return { contents: (await compile(`@tailwind base;`)).css!, loader: "css", @@ -358,6 +358,13 @@ const esbuildPlugin = ( const vitePlugin = (styleMap: Map, compile: Compile): vite.Plugin => ({ name: "tailwind", resolveId(id, importer) { + if (id === `${name}/base`) { + return { + id: ROLLUP_PREFIX + "directive:base", + moduleSideEffects: true, + }; + } + if (id.startsWith("tailwind:")) { const resolved = join(dirname(importer!), id.slice("tailwind:".length)); if (styleMap.has(resolved)) { @@ -371,6 +378,10 @@ const vitePlugin = (styleMap: Map, compile: Compile): vite.Plugi async load(id: string) { if (id.startsWith(ROLLUP_PREFIX)) { const resolved = id.slice(ROLLUP_PREFIX.length); + if (resolved === "directive:base") { + return (await compile("@tailwind base;")).css; + } + if (styleMap.has(resolved)) { const result = await compile(styleMap.get(resolved)!); return result.css;