Add rollup
This commit is contained in:
parent
1109ff0dea
commit
39851182ec
@ -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);
|
||||
|
15
src/index.ts
15
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<string, string>, 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<string, string>, 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user