Skip to content

Commit fc84616

Browse files
packages(ui): build step using rollup + tsc (themesberg#1344)
* refactor: packages(ui) - use `rollup` to build and transpile + tsc for dts files [WIP] * chore: packages(ui) - remove `rollup-plugin-delete` replace with local plugin using `rimraf` * fix: packages(ui) - build step generateDts overriding the rest * fix: packages(ui) - rework tsconfig files chore: apps(web) - update `tailwind.config` to use `.mjs` * feat: packages(ui) - create tailwind plugin for easier management of the `content` and `plugins` values for `tailwind.config.js` - change build output folder from `lib` to `dist` - chore: apps(web): use new plugi in `tailwind.config` * feat: packages(ui) - remove tailwind plugin and replace it with `tailwind` file which exports getters for `content` and `plugin` chore: apps(web): use new `flowbite-react/tailwind` in `tailwind.config` * chore: remove comments * chore: remove unused package * chore: remove rollup external leftover path * chore: add `trustedDependencies` for `postinstall` script to work in CI env * chore: get rid of `postinstall` lifecycle script and configure turborepo to handle the sequence of `apps/web` build and dev scripts * fix: turborepo `packages/ui` script dependencies * chore: rollup config - remove redundant array structure * chore: simplify turbo configs + fix `packages/ui` outputs path * chore: update docs introduction and installation guides to new config * fix: docs redwood guide tailwind config path * chore: remove comment * fix: docs redwood guide tailwind config path typo * chore: add changeset * Update .changeset/hungry-toys-care.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update .changeset/hungry-toys-care.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update .changeset/hungry-toys-care.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update .changeset/hungry-toys-care.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * chore: bump version minor --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 971e49f commit fc84616

8 files changed

+169
-40
lines changed

.eslintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = {
4040
classRegex: "^(class(Name)|theme)?$",
4141
},
4242
},
43-
ignorePatterns: ["lib"],
43+
ignorePatterns: ["dist"],
4444
rules: {
4545
"no-undef": "off",
4646
"react/prop-types": "off",

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
coverage
2-
lib
2+
dist

package.json

+22-18
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,32 @@
2121
"license": "MIT",
2222
"exports": {
2323
".": {
24-
"types": "./lib/types/index.d.ts",
25-
"import": "./lib/esm/index.js",
26-
"require": "./lib/cjs/index.js"
24+
"types": "./dist/types/index.d.ts",
25+
"import": "./dist/esm/index.mjs",
26+
"require": "./dist/cjs/index.cjs"
2727
},
2828
"./components/*": {
29-
"types": "./lib/types/components/*/index.d.ts",
30-
"import": "./lib/esm/components/*/index.js",
31-
"require": "./lib/cjs/components/*/index.js"
29+
"types": "./dist/types/components/*/index.d.ts",
30+
"import": "./dist/esm/components/*/index.mjs",
31+
"require": "./dist/cjs/components/*/index.cjs"
32+
},
33+
"./tailwind": {
34+
"types": "./dist/types/tailwind.d.ts",
35+
"import": "./dist/esm/tailwind.mjs",
36+
"require": "./dist/cjs/tailwind.cjs"
3237
},
3338
"./package.json": "./package.json"
3439
},
35-
"main": "lib/cjs/index.js",
36-
"module": "lib/esm/index.js",
37-
"types": "lib/types/index.d.ts",
40+
"main": "dist/cjs/index.cjs",
41+
"module": "dist/esm/index.mjs",
42+
"types": "dist/types/index.d.ts",
3843
"files": [
39-
"lib"
44+
"dist"
4045
],
4146
"scripts": {
42-
"build": "rimraf lib && bun build:fast",
43-
"build:cjs": "tsc -p tsconfig.build.json --module CommonJS --outDir lib/cjs",
44-
"build:esm": "tsc -p tsconfig.build.json --module ESNext --outDir lib/esm",
45-
"build:fast": "bun build:cjs && bun build:esm && bun build:types",
46-
"build:types": "tsc -p tsconfig.build.json --declaration --emitDeclarationOnly --outDir lib/types",
47-
"clean": "rimraf .turbo coverage lib node_modules tsconfig.tsbuildinfo",
48-
"dev": "bun build:fast --watch",
47+
"build": "bun --bun rollup -c",
48+
"clean": "rimraf .turbo coverage dist node_modules tsconfig.tsbuildinfo",
49+
"dev": "bun run build --watch",
4950
"format": "prettier . --write",
5051
"format:check": "prettier . --check",
5152
"lint": "eslint .",
@@ -78,8 +79,11 @@
7879
"eslint-plugin-react": "7.34.1",
7980
"eslint-plugin-storybook": "0.8.0",
8081
"eslint-plugin-vitest": "0.4.1",
82+
"fast-glob": "3.3.2",
8183
"jsdom": "24.0.0",
82-
"mime": "^4.0.1",
84+
"rollup": "4.13.2",
85+
"rollup-plugin-esbuild": "6.1.1",
86+
"rollup-plugin-use-client": "1.4.0",
8387
"typescript": "5.4.3",
8488
"vitest": "1.4.0"
8589
},

rollup.config.mjs

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { $ } from "bun";
2+
import glob from "fast-glob";
3+
import { rimraf } from "rimraf";
4+
import esbuild from "rollup-plugin-esbuild";
5+
import { rollupPluginUseClient } from "rollup-plugin-use-client";
6+
import packageJson from "./package.json";
7+
8+
const componentEntries = await glob("src/components/**/index.ts");
9+
const entries = ["src/index.ts", "src/tailwind.ts", ...componentEntries];
10+
const external = [
11+
"flowbite/plugin",
12+
"react-icons/fa",
13+
"react-icons/hi",
14+
"react/jsx-runtime",
15+
...Object.keys({
16+
...packageJson.dependencies,
17+
...packageJson.peerDependencies,
18+
}),
19+
];
20+
const outputDir = "dist";
21+
22+
/**
23+
* @type {import('rollup').RollupOptions}
24+
*/
25+
export default {
26+
input: entries,
27+
output: [
28+
{
29+
format: "es",
30+
dir: `${outputDir}/esm`,
31+
entryFileNames: "[name].mjs",
32+
preserveModules: true,
33+
sourcemap: true,
34+
},
35+
{
36+
format: "cjs",
37+
dir: `${outputDir}/cjs`,
38+
entryFileNames: "[name].cjs",
39+
preserveModules: true,
40+
sourcemap: true,
41+
},
42+
],
43+
external,
44+
plugins: [
45+
cleanOutputDir(),
46+
esbuild({
47+
sourceMap: false,
48+
}),
49+
rollupPluginUseClient(),
50+
generateDts(),
51+
],
52+
onwarn(warning, warn) {
53+
if (warning.code === "MODULE_LEVEL_DIRECTIVE") {
54+
return;
55+
}
56+
warn(warning);
57+
},
58+
};
59+
60+
function cleanOutputDir() {
61+
return {
62+
name: "clean-output-dir",
63+
async buildStart() {
64+
await rimraf(outputDir);
65+
},
66+
};
67+
}
68+
69+
function generateDts() {
70+
return {
71+
name: "generate-dts",
72+
async closeBundle() {
73+
await $`tsc -p tsconfig.build.json --outDir ${outputDir}/types`;
74+
},
75+
};
76+
}

src/tailwind.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import flowbitePlugin from "flowbite/plugin";
2+
3+
interface Content {
4+
/**
5+
* Path to `node_modules` where `flowbite-react` is installed
6+
*
7+
* ===============================================
8+
*
9+
* For monorepo setup where `flowbite-react` is installed in the root `node_modules` but used in `apps/web` directory
10+
* @example
11+
* ```
12+
* // tailwind.config.(js|cjs|mjs) file
13+
*
14+
* // cjs
15+
* const flowbite = require("flowbite-react/tailwind");
16+
* // esm
17+
* import flowbite from "flowbite-react/tailwind";
18+
*
19+
* {
20+
* content: [
21+
* // ...
22+
* flowbite.content({ base: "../../" })
23+
* ],
24+
* plugins: [
25+
* // ...
26+
* flowbite.plugin()
27+
* ]
28+
* }
29+
* ```
30+
*
31+
* @default "./"
32+
*/
33+
base?: string;
34+
}
35+
36+
export function content({ base = "./" }: Content = {}) {
37+
const path = "node_modules/flowbite-react/dist/esm/**/*.mjs";
38+
39+
return `${base}${path}`;
40+
}
41+
42+
export function plugin() {
43+
return flowbitePlugin;
44+
}

tsconfig.build.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"incremental": false,
5-
"sourceMap": true,
6-
"jsx": "react-jsx"
4+
"declaration": true,
5+
"emitDeclarationOnly": true
76
},
87
"include": ["src"],
9-
"exclude": ["lib", "**/*.spec.ts", "**/*.spec.tsx", "**/*.stories.tsx"]
8+
"exclude": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.stories.tsx"]
109
}

tsconfig.json

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
{
22
"compilerOptions": {
3-
"allowJs": true,
3+
/* Language and Environment */
4+
"target": "ESNext",
5+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
6+
"jsx": "react-jsx",
7+
8+
/* Modules */
9+
"module": "NodeNext",
10+
"moduleResolution": "NodeNext",
11+
"resolveJsonModule": true,
12+
13+
/* Interop Constraints */
14+
"isolatedModules": true,
15+
"allowSyntheticDefaultImports": true,
416
"esModuleInterop": true,
517
"forceConsistentCasingInFileNames": true,
6-
"incremental": true,
7-
"isolatedModules": true,
8-
"jsx": "preserve",
9-
"lib": ["DOM", "DOM.Iterable", "ESNext"],
10-
"module": "ESNext",
11-
"moduleResolution": "node",
12-
"noEmit": false,
18+
19+
/* Type Checking */
20+
"strict": true,
1321
"noImplicitAny": true,
14-
"noImplicitThis": true,
1522
"noUnusedLocals": true,
1623
"noUnusedParameters": true,
17-
"resolveJsonModule": true,
18-
"skipLibCheck": true,
19-
"strict": true,
20-
"target": "ESNext"
24+
"noFallthroughCasesInSwitch": true,
25+
26+
/* Completeness */
27+
"skipLibCheck": true
2128
},
22-
"include": ["**/*.ts", "**/*.tsx"],
23-
"exclude": ["lib"]
29+
"include": ["**/*.ts", "**/*.tsx"]
2430
}

turbo.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": ["//"],
33
"pipeline": {
44
"build": {
5-
"outputs": ["lib/**"]
5+
"outputs": ["dist/**"]
66
}
77
}
88
}

0 commit comments

Comments
 (0)