@bunup/plugin-tailwindcss 0.11.28 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @bunup/plugin-tailwindcss
2
2
 
3
- The official Bunup plugin for creating libraries with Tailwind CSS.
3
+ A plugin for Bunup that provides seamless integration with Tailwind CSS.
4
4
 
5
5
  Learn more: https://bunup.dev/docs/builtin-plugins/tailwindcss
@@ -0,0 +1,31 @@
1
+ import { BunPlugin } from "bun";
2
+ import { Plugin } from "postcss";
3
+ type TailwindCSSOptions = {
4
+ /**
5
+ * Whether to inject CSS styles dynamically into the document head at runtime
6
+ * instead of bundling them to the build output.
7
+ * @default false
8
+ */
9
+ inject?: boolean
10
+ /**
11
+ * Whether to minify the generated CSS output.
12
+ * @default false
13
+ */
14
+ minify?: boolean
15
+ /**
16
+ * Whether to include Tailwind's preflight styles (CSS reset).
17
+ * @default false
18
+ */
19
+ preflight?: boolean
20
+ /**
21
+ * Additional PostCSS plugins to apply during CSS processing.
22
+ */
23
+ postcssPlugins?: Plugin[]
24
+ };
25
+ /**
26
+ * A plugin for Bunup that provides seamless integration with Tailwind CSS.
27
+ *
28
+ * @see https://bunup.dev/docs/recipes/tailwindcss
29
+ */
30
+ declare function tailwindcss(options?: TailwindCSSOptions): BunPlugin;
31
+ export { tailwindcss, tailwindcss as default };
package/dist/index.js ADDED
@@ -0,0 +1,97 @@
1
+ // packages/plugin-tailwindcss/src/index.ts
2
+ import path from "node:path";
3
+ import { getDefaultCssBrowserTargets } from "@bunup/shared";
4
+ import tailwindPostcss from "@tailwindcss/postcss";
5
+ import { transform } from "lightningcss";
6
+ import postcss from "postcss";
7
+ function tailwindcss(options = {}) {
8
+ return {
9
+ name: "bunup:tailwindcss",
10
+ setup: (build) => {
11
+ const { inject, minify, preflight, postcssPlugins } = options;
12
+ if (inject) {
13
+ build.onResolve({ filter: /^__inject-style$/ }, () => {
14
+ return {
15
+ path: "__inject-style",
16
+ namespace: "__inject-style"
17
+ };
18
+ });
19
+ build.onLoad({ filter: /^__inject-style$/, namespace: "__inject-style" }, () => {
20
+ return {
21
+ contents: `
22
+ export default function injectStyle(css) {
23
+ if (!css || typeof document === 'undefined') return
24
+
25
+ const head = document.head || document.getElementsByTagName('head')[0]
26
+ const style = document.createElement('style')
27
+ head.appendChild(style)
28
+
29
+ if (style.styleSheet) {
30
+ style.styleSheet.cssText = css
31
+ } else {
32
+ style.appendChild(document.createTextNode(css))
33
+ }
34
+ }
35
+ `,
36
+ loader: "js"
37
+ };
38
+ });
39
+ }
40
+ build.onLoad({ filter: /\.css$/ }, async (args) => {
41
+ const source = await Bun.file(args.path).text();
42
+ const cssFromTailwind = (await postcss([
43
+ tailwindPostcss({
44
+ base: build.config.root,
45
+ transformAssetUrls: false
46
+ }),
47
+ ...postcssPlugins ?? []
48
+ ]).process(preprocessSource(source, preflight), {
49
+ from: args.path
50
+ })).css;
51
+ const { code: css } = transform({
52
+ filename: path.basename(args.path),
53
+ code: Buffer.from(cssFromTailwind),
54
+ minify: minify ?? !!build.config.minify,
55
+ targets: getDefaultCssBrowserTargets()
56
+ });
57
+ if (inject) {
58
+ return {
59
+ contents: `import injectStyle from '__inject-style';injectStyle(${JSON.stringify(css)})`,
60
+ loader: "js"
61
+ };
62
+ }
63
+ return {
64
+ contents: css,
65
+ loader: "css"
66
+ };
67
+ });
68
+ }
69
+ };
70
+ }
71
+ var src_default = tailwindcss;
72
+ var TAILWIND_IMPORT_RE = /^[\s]*@import\s+["']tailwindcss[^"']*["'][^;]*;[\s]*$/gm;
73
+ var PREFIX_RE = /^[\s]*@import\s+["']tailwindcss[^"']*["'][^;]*prefix\(([^)]+)\)[^;]*;[\s]*$/gm;
74
+ function extractPrefix(source) {
75
+ const match = source.match(PREFIX_RE);
76
+ if (match) {
77
+ const prefixMatch = match[0].match(/prefix\(([^)]+)\)/);
78
+ return prefixMatch ? prefixMatch[1] : null;
79
+ }
80
+ return null;
81
+ }
82
+ function preprocessSource(source, preflight) {
83
+ const prefix = extractPrefix(source);
84
+ const removedTailwindImports = source.replace(TAILWIND_IMPORT_RE, "");
85
+ return `
86
+ @layer theme, base, components, utilities;
87
+ @import "tailwindcss/theme.css" layer(theme)${prefix ? ` prefix(${prefix});` : ";"};
88
+ ${preflight ? `@import "tailwindcss/preflight.css" layer(base)${prefix ? ` prefix(${prefix});` : ";"};` : ""}
89
+ @import "tailwindcss/utilities.css" layer(utilities)${prefix ? ` prefix(${prefix});` : ";"};
90
+ @source not inline("{contents,filter,transform}");
91
+ ${removedTailwindImports}
92
+ `.trim();
93
+ }
94
+ export {
95
+ tailwindcss,
96
+ src_default as default
97
+ };
package/package.json CHANGED
@@ -1,13 +1,21 @@
1
1
  {
2
2
  "name": "@bunup/plugin-tailwindcss",
3
- "description": "The official Bunup plugin for creating libraries with Tailwind CSS.",
4
- "version": "0.11.28",
5
- "type": "module",
6
- "files": [
7
- "dist"
8
- ],
3
+ "version": "0.13.0",
4
+ "author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/bunup/bunup.git"
8
+ },
9
9
  "module": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
10
+ "dependencies": {
11
+ "@tailwindcss/postcss": "^4.1.13",
12
+ "lightningcss": "^1.30.1",
13
+ "postcss": "^8.5.6",
14
+ "@bunup/shared": "0.11.30"
15
+ },
16
+ "peerDependencies": {
17
+ "typescript": ">=4.5.0"
18
+ },
11
19
  "exports": {
12
20
  ".": {
13
21
  "import": {
@@ -17,8 +25,18 @@
17
25
  },
18
26
  "./package.json": "./package.json"
19
27
  },
28
+ "description": "A plugin for Bunup that provides seamless integration with Tailwind CSS.",
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "funding": "https://github.com/sponsors/arshad-yaseen",
33
+ "homepage": "https://bunup.dev",
34
+ "keywords": [
35
+ "bunup",
36
+ "tailwindcss",
37
+ "bunup-tailwindcss"
38
+ ],
20
39
  "license": "MIT",
21
- "author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
22
40
  "maintainers": [
23
41
  {
24
42
  "name": "Arshad Yaseen",
@@ -26,28 +44,11 @@
26
44
  "url": "https://arshadyaseen.com"
27
45
  }
28
46
  ],
29
- "keywords": [
30
- "bunup",
31
- "tailwindcss",
32
- "bunup-tailwindcss"
33
- ],
34
- "repository": {
35
- "type": "git",
36
- "url": "git+https://github.com/bunup/bunup.git"
37
- },
38
- "funding": "https://github.com/sponsors/arshad-yaseen",
39
- "homepage": "https://bunup.dev",
40
- "peerDependencies": {
41
- "typescript": ">=4.5.0"
42
- },
43
47
  "peerDependenciesMeta": {
44
48
  "typescript": {
45
49
  "optional": true
46
50
  }
47
51
  },
48
- "dependencies": {
49
- "@tailwindcss/postcss": "^4.1.13",
50
- "lightningcss": "^1.30.1",
51
- "postcss": "^8.5.6"
52
- }
52
+ "type": "module",
53
+ "types": "./dist/index.d.ts"
53
54
  }