@bunup/plugin-tailwindcss 0.11.23
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 +5 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +54 -0
- package/package.json +52 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BunPlugin } from "bun";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the TailwindCSS plugin
|
|
4
|
+
*/
|
|
5
|
+
type TailwindCSSOptions = {
|
|
6
|
+
/** CSS class prefix to apply for scoping. Defaults to 'bunup' */
|
|
7
|
+
prefix?: string
|
|
8
|
+
};
|
|
9
|
+
declare function tailwindcss(options?: TailwindCSSOptions): BunPlugin;
|
|
10
|
+
export { tailwindcss as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// packages/plugin-tailwindcss/src/index.ts
|
|
2
|
+
import tailwindPostcss from "@tailwindcss/postcss";
|
|
3
|
+
import postcss from "postcss";
|
|
4
|
+
function tailwindcss(options = {}) {
|
|
5
|
+
return {
|
|
6
|
+
name: "bunup:tailwindcss",
|
|
7
|
+
setup: (build) => {
|
|
8
|
+
const { prefix = "bunup" } = options;
|
|
9
|
+
const rewriter = new HTMLRewriter;
|
|
10
|
+
build.onLoad({ filter: /\.(tsx|jsx)$/ }, async (args) => {
|
|
11
|
+
const source = await Bun.file(args.path).text();
|
|
12
|
+
rewriter.on("*", {
|
|
13
|
+
element(elem) {
|
|
14
|
+
const currentClassName = elem.getAttribute("className");
|
|
15
|
+
const scopedClassName = currentClassName?.split(" ").map((c) => `${!c.includes(prefix) ? `${prefix}-` : ""}${c}`).join(" ");
|
|
16
|
+
if (scopedClassName)
|
|
17
|
+
elem.setAttribute("className", scopedClassName);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const result = rewriter.transform(source);
|
|
21
|
+
return {
|
|
22
|
+
loader: args.path.endsWith(".tsx") ? "tsx" : "jsx",
|
|
23
|
+
contents: result
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
build.onLoad({ filter: /\.css$/ }, async (args) => {
|
|
27
|
+
const source = await Bun.file(args.path).text();
|
|
28
|
+
const result = await postcss([
|
|
29
|
+
tailwindPostcss({
|
|
30
|
+
base: build.config.root,
|
|
31
|
+
transformAssetUrls: false
|
|
32
|
+
}),
|
|
33
|
+
{
|
|
34
|
+
postcssPlugin: "scoping",
|
|
35
|
+
Rule(rule) {
|
|
36
|
+
rule.selector = rule.selector.replace(/\.([\w-\\/]+)/g, (_, cls) => {
|
|
37
|
+
return `.${prefix}-${cls}`;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
]).process(source, {
|
|
42
|
+
from: args.path
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
contents: result.css,
|
|
46
|
+
loader: "css"
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
tailwindcss as default
|
|
54
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bunup/plugin-tailwindcss",
|
|
3
|
+
"description": "A Bunup plugin that provides seamless integration with Tailwind CSS",
|
|
4
|
+
"version": "0.11.23",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
|
|
21
|
+
"maintainers": [
|
|
22
|
+
{
|
|
23
|
+
"name": "Arshad Yaseen",
|
|
24
|
+
"email": "m@arshadyaseen.com",
|
|
25
|
+
"url": "https://arshadyaseen.com"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"keywords": [
|
|
29
|
+
"bunup",
|
|
30
|
+
"plugin",
|
|
31
|
+
"tailwind",
|
|
32
|
+
"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
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"typescript": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@tailwindcss/postcss": "^4.1.12",
|
|
50
|
+
"postcss": "^8.5.6"
|
|
51
|
+
}
|
|
52
|
+
}
|