tailwind-to-style 2.7.7 → 2.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-to-style",
3
- "version": "2.7.7",
3
+ "version": "2.8.0",
4
4
  "description": "Convert tailwind classes to inline style",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -10,7 +10,8 @@
10
10
  "dist",
11
11
  "preflight.css",
12
12
  "README.md",
13
- "LICENSE"
13
+ "LICENSE",
14
+ "plugins"
14
15
  ],
15
16
  "scripts": {
16
17
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --passWithNoTests",
@@ -0,0 +1,40 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { twsx } = require("tailwind-to-style");
4
+
5
+ function buildTwsx(twsxDir, outDir) {
6
+ let allCss = "";
7
+ fs.readdirSync(twsxDir).forEach((file) => {
8
+ if (file.endsWith(".json")) {
9
+ const json = JSON.parse(
10
+ fs.readFileSync(path.join(twsxDir, file), "utf8")
11
+ );
12
+ const css = twsx(json, { inject: false });
13
+ const outFile = path.join(outDir, file.replace(".json", ".css"));
14
+ fs.writeFileSync(outFile, css);
15
+ allCss += css + "\n";
16
+ }
17
+ });
18
+ return allCss;
19
+ }
20
+
21
+ module.exports = function twsxPlugin(options = {}) {
22
+ const twsxDir = options.twsxDir || path.resolve(process.cwd(), "src/twsx");
23
+ const outDir = options.outDir || path.resolve(process.cwd(), "dist");
24
+ const cssFile = path.resolve(
25
+ process.cwd(),
26
+ "node_modules/tailwind-to-style/twsx.css"
27
+ );
28
+
29
+ return {
30
+ name: "vite-twsx",
31
+ buildStart() {
32
+ const allCss = buildTwsx(twsxDir, outDir);
33
+ fs.writeFileSync(cssFile, allCss);
34
+ },
35
+ handleHotUpdate() {
36
+ const allCss = buildTwsx(twsxDir, outDir);
37
+ fs.writeFileSync(cssFile, allCss);
38
+ },
39
+ };
40
+ };
@@ -0,0 +1,43 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { twsx } = require("tailwind-to-style");
4
+
5
+ class TwsxPlugin {
6
+ constructor(options = {}) {
7
+ this.twsxDir = options.twsxDir || path.resolve(process.cwd(), "src/twsx");
8
+ this.outDir = options.outDir || path.resolve(process.cwd(), "dist");
9
+ }
10
+
11
+ buildTwsx() {
12
+ let allCss = "";
13
+ fs.readdirSync(this.twsxDir).forEach((file) => {
14
+ if (file.endsWith(".json")) {
15
+ const json = JSON.parse(
16
+ fs.readFileSync(path.join(this.twsxDir, file), "utf8")
17
+ );
18
+ const css = twsx(json, { inject: false });
19
+ const outFile = path.join(this.outDir, file.replace(".json", ".css"));
20
+ fs.writeFileSync(outFile, css);
21
+ allCss += css + "\n";
22
+ }
23
+ });
24
+ return allCss;
25
+ }
26
+
27
+ apply(compiler) {
28
+ const cssFile = path.resolve(
29
+ process.cwd(),
30
+ "node_modules/tailwind-to-style/twsx.css"
31
+ );
32
+ compiler.hooks.beforeCompile.tap("TwsxPlugin", () => {
33
+ const allCss = this.buildTwsx();
34
+ fs.writeFileSync(cssFile, allCss);
35
+ });
36
+ compiler.hooks.watchRun.tap("TwsxPlugin", () => {
37
+ const allCss = this.buildTwsx();
38
+ fs.writeFileSync(cssFile, allCss);
39
+ });
40
+ }
41
+ }
42
+
43
+ module.exports = TwsxPlugin;