Add rollup
This commit is contained in:
parent
1109ff0dea
commit
39851182ec
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env bun
|
#!/usr/bin/env bun
|
||||||
import { type Options, build } from "tsup";
|
import { type Options, build } from "tsup";
|
||||||
|
import { promises as fs } from "node:fs";
|
||||||
import tsupConfig from "../tsup.config";
|
import tsupConfig from "../tsup.config";
|
||||||
import { pick } from "lodash";
|
import { pick } from "lodash";
|
||||||
import pkg from "../package.json" with { type: "json" };
|
import pkg from "../package.json" with { type: "json" };
|
||||||
@ -18,4 +19,7 @@ await Bun.write(
|
|||||||
`dist/base.d.ts`,
|
`dist/base.d.ts`,
|
||||||
`/**\n * \`@tailwind base\` component.\n */\nexport {};`
|
`/**\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);
|
process.exit(0);
|
||||||
|
15
src/index.ts
15
src/index.ts
@ -332,12 +332,12 @@ const esbuildPlugin = (
|
|||||||
});
|
});
|
||||||
|
|
||||||
build.onResolve({ filter: RegExp(`^${name}/base$`) }, () => ({
|
build.onResolve({ filter: RegExp(`^${name}/base$`) }, () => ({
|
||||||
path: "directive:babel",
|
path: "directive:base",
|
||||||
namespace: ESBUILD_NAMESPACE,
|
namespace: ESBUILD_NAMESPACE,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
build.onLoad({ filter: /.*/, namespace: ESBUILD_NAMESPACE }, async ({ path }) => {
|
build.onLoad({ filter: /.*/, namespace: ESBUILD_NAMESPACE }, async ({ path }) => {
|
||||||
if (path === "directive:babel") {
|
if (path === "directive:base") {
|
||||||
return {
|
return {
|
||||||
contents: (await compile(`@tailwind base;`)).css!,
|
contents: (await compile(`@tailwind base;`)).css!,
|
||||||
loader: "css",
|
loader: "css",
|
||||||
@ -358,6 +358,13 @@ const esbuildPlugin = (
|
|||||||
const vitePlugin = (styleMap: Map<string, string>, compile: Compile): vite.Plugin => ({
|
const vitePlugin = (styleMap: Map<string, string>, compile: Compile): vite.Plugin => ({
|
||||||
name: "tailwind",
|
name: "tailwind",
|
||||||
resolveId(id, importer) {
|
resolveId(id, importer) {
|
||||||
|
if (id === `${name}/base`) {
|
||||||
|
return {
|
||||||
|
id: ROLLUP_PREFIX + "directive:base",
|
||||||
|
moduleSideEffects: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (id.startsWith("tailwind:")) {
|
if (id.startsWith("tailwind:")) {
|
||||||
const resolved = join(dirname(importer!), id.slice("tailwind:".length));
|
const resolved = join(dirname(importer!), id.slice("tailwind:".length));
|
||||||
if (styleMap.has(resolved)) {
|
if (styleMap.has(resolved)) {
|
||||||
@ -371,6 +378,10 @@ const vitePlugin = (styleMap: Map<string, string>, compile: Compile): vite.Plugi
|
|||||||
async load(id: string) {
|
async load(id: string) {
|
||||||
if (id.startsWith(ROLLUP_PREFIX)) {
|
if (id.startsWith(ROLLUP_PREFIX)) {
|
||||||
const resolved = id.slice(ROLLUP_PREFIX.length);
|
const resolved = id.slice(ROLLUP_PREFIX.length);
|
||||||
|
if (resolved === "directive:base") {
|
||||||
|
return (await compile("@tailwind base;")).css;
|
||||||
|
}
|
||||||
|
|
||||||
if (styleMap.has(resolved)) {
|
if (styleMap.has(resolved)) {
|
||||||
const result = await compile(styleMap.get(resolved)!);
|
const result = await compile(styleMap.get(resolved)!);
|
||||||
return result.css;
|
return result.css;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user