tailwind-to-style 2.8.2 → 2.8.4

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
@@ -490,82 +490,93 @@ This will automatically log warnings for operations taking longer than 5ms and p
490
490
 
491
491
  ### Automated Modular CSS Generation
492
492
 
493
- 1. Save your modular styles in the `src/twsx/` folder as JS files (e.g., `card.js`, `button.js`).
493
+ 1. Create JS files with `twsx.` prefix in your project (e.g., `twsx.card.js`, `twsx.button.js`) anywhere in your `src/` folder.
494
494
  2. Use the Vite/Webpack plugin from the `plugins/` folder to automatically generate CSS on every build/rebuild.
495
- 3. All generated CSS files will be merged into a single `twsx.css` file inside `node_modules/tailwind-to-style/`.
496
- 4. In React, simply import this file in your entry point: `import 'tailwind-to-style/twsx.css'`.
495
+ 3. Each JS file will generate its own CSS file in the specified output directory (default: `src/styles/`).
496
+ 4. Import the generated CSS files directly in your components or bundle them as needed.
497
497
 
498
498
  #### Vite Plugin Usage Example
499
499
 
500
500
  Add the plugin to your `vite.config.js`:
501
501
  ```js
502
- import twsxPlugin from './plugins/vite-twsx';
502
+ import twsxPlugin from 'tailwind-to-style/plugins/vite-twsx';
503
503
 
504
504
  export default {
505
505
  plugins: [
506
506
  twsxPlugin({
507
- twsxDir: 'src/twsx',
508
- outDir: 'dist'
507
+ inputDir: 'src',
508
+ outputDir: 'src/styles'
509
509
  })
510
510
  ]
511
511
  };
512
512
  ```
513
513
 
514
- After build, the merged CSS file will be automatically created at `node_modules/tailwind-to-style/twsx.css`.
515
- Import in React:
514
+ After build, individual CSS files will be created in `src/styles/` (e.g., `twsx.card.css`, `twsx.button.css`).
515
+ Import in your components:
516
516
  ```js
517
- // src/index.js
518
- import 'tailwind-to-style/twsx.css';
517
+ // Import specific CSS files
518
+ import './styles/twsx.card.css';
519
+ import './styles/twsx.button.css';
519
520
  ```
520
521
 
521
522
  #### Webpack Plugin Usage Example
522
523
 
523
524
  Add the plugin to your `webpack.config.js`:
524
525
  ```js
525
- import TwsxPlugin from './plugins/webpack-twsx';
526
+ import TwsxPlugin from 'tailwind-to-style/plugins/webpack-twsx';
526
527
 
527
528
  module.exports = {
528
529
  plugins: [
529
530
  new TwsxPlugin({
530
- twsxDir: 'src/twsx',
531
- outDir: 'dist'
531
+ inputDir: 'src',
532
+ outputDir: 'src/styles'
532
533
  })
533
534
  ]
534
535
  };
535
536
  ```
536
537
 
537
- After build, the merged CSS file will be automatically created at `node_modules/tailwind-to-style/twsx.css`.
538
- Import in React:
538
+ After build, individual CSS files will be created in `src/styles/` (e.g., `twsx.card.css`, `twsx.button.css`).
539
+ Import in your components:
539
540
  ```js
540
- // src/index.js
541
- import 'tailwind-to-style/twsx.css';
541
+ // Import specific CSS files
542
+ import './styles/twsx.card.css';
543
+ import './styles/twsx.button.css';
542
544
  ```
543
545
 
544
546
  ## Build-Time CSS Generation via Script
545
547
 
546
- In addition to using the Vite/Webpack plugin, you can also use a Node.js script to generate a CSS file from the `src/twsx` folder manually or as part of your build workflow.
548
+ In addition to using the Vite/Webpack plugin, you can also use a Node.js script to generate CSS files from `twsx.*.js` files manually or as part of your build workflow.
547
549
 
548
- ### Script: lib/build-twsx.js
550
+ ### Script: tailwind-to-style/lib/build-twsx.js
549
551
 
550
- This script will read all JS files in `src/twsx`, generate CSS using the `twsx` function, and write the result to `node_modules/tailwind-to-style/twsx.css`.
552
+ This script will recursively scan for all `twsx.*.js` files in your project, generate CSS using the `twsx` function, and write individual CSS files to the specified output directory.
551
553
 
552
554
  #### How to Use
553
555
 
554
- 1. Make sure your JS files containing style objects are in `src/twsx`.
556
+ 1. Create JS files with `twsx.` prefix containing style objects anywhere in your `src/` folder (e.g., `src/components/twsx.card.js`).
555
557
  2. Run the script with the following command:
556
558
 
557
559
  ```bash
558
- node lib/build-twsx.js
560
+ node tailwind-to-style/lib/build-twsx.js
559
561
  ```
560
- 3. After running, the combined CSS file will be available at:
561
562
 
563
+ You can configure input and output directories using environment variables:
564
+ ```bash
565
+ TWSX_INPUT_DIR=src TWSX_OUTPUT_DIR=dist/styles node tailwind-to-style/lib/build-twsx.js
562
566
  ```
563
- node_modules/tailwind-to-style/twsx.css
567
+
568
+ 3. After running, individual CSS files will be available in the output directory (default: `src/styles/`):
569
+
564
570
  ```
565
- 4. Import this CSS file in your React entry point:
571
+ src/styles/twsx.card.css
572
+ src/styles/twsx.button.css
573
+ ```
574
+
575
+ 4. Import the generated CSS files in your components:
566
576
 
567
577
  ```js
568
- import 'tailwind-to-style/twsx.css';
578
+ import './styles/twsx.card.css';
579
+ import './styles/twsx.button.css';
569
580
  ```
570
581
 
571
582
  #### Automatic Integration
@@ -575,7 +586,7 @@ You can add this script to the build section in your `package.json`:
575
586
  ```json
576
587
  {
577
588
  "scripts": {
578
- "build-css": "node lib/build-twsx.js"
589
+ "build-css": "node tailwind-to-style/lib/build-twsx.js"
579
590
  }
580
591
  }
581
592
  ```
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v2.8.2
2
+ * tailwind-to-style v2.8.4
3
3
  * Convert tailwind classes to inline style
4
4
  *
5
5
  * @author Bigetion
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v2.8.2
2
+ * tailwind-to-style v2.8.4
3
3
  * Convert tailwind classes to inline style
4
4
  *
5
5
  * @author Bigetion
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v2.8.2
2
+ * tailwind-to-style v2.8.4
3
3
  * Convert tailwind classes to inline style
4
4
  *
5
5
  * @author Bigetion
package/lib/build-twsx.js CHANGED
@@ -30,7 +30,6 @@ async function buildTwsx(inputDir, outputDir) {
30
30
  const fileName = path.basename(filePath).replace(/\.js$/, ".css");
31
31
  const cssFilePath = path.join(outputDir, fileName);
32
32
  fs.writeFileSync(cssFilePath, css);
33
- console.log(`[build-twsx] CSS written to ${cssFilePath}`);
34
33
  } catch (err) {
35
34
  console.error(
36
35
  `[build-twsx] Error importing or processing ${filePath}:`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-to-style",
3
- "version": "2.8.2",
3
+ "version": "2.8.4",
4
4
  "description": "Convert tailwind classes to inline style",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -20,6 +20,9 @@ function findTwsxFiles(dir, files = []) {
20
20
  async function buildTwsx(inputDir, outputDir) {
21
21
  try {
22
22
  const twsxFiles = findTwsxFiles(inputDir);
23
+ const generatedCssFiles = [];
24
+
25
+ // Generate CSS from JS files
23
26
  for (const filePath of twsxFiles) {
24
27
  try {
25
28
  const styleModule = await import(
@@ -30,6 +33,7 @@ async function buildTwsx(inputDir, outputDir) {
30
33
  const fileName = path.basename(filePath).replace(/\.js$/, ".css");
31
34
  const cssFilePath = path.join(outputDir, fileName);
32
35
  fs.writeFileSync(cssFilePath, css);
36
+ generatedCssFiles.push(fileName);
33
37
  } catch (err) {
34
38
  console.error(
35
39
  `[vite-twsx] Error importing or processing ${filePath}:`,
@@ -37,6 +41,20 @@ async function buildTwsx(inputDir, outputDir) {
37
41
  );
38
42
  }
39
43
  }
44
+
45
+ // Clean up orphaned CSS files
46
+ if (fs.existsSync(outputDir)) {
47
+ const existingCssFiles = fs
48
+ .readdirSync(outputDir)
49
+ .filter((file) => file.startsWith("twsx.") && file.endsWith(".css"));
50
+
51
+ for (const cssFile of existingCssFiles) {
52
+ if (!generatedCssFiles.includes(cssFile)) {
53
+ const cssFilePath = path.join(outputDir, cssFile);
54
+ fs.unlinkSync(cssFilePath);
55
+ }
56
+ }
57
+ }
40
58
  } catch (err) {
41
59
  console.error("[vite-twsx] Error scanning for twsx files:", err);
42
60
  }
@@ -20,6 +20,9 @@ function findTwsxFiles(dir, files = []) {
20
20
  async function buildTwsx(inputDir, outputDir) {
21
21
  try {
22
22
  const twsxFiles = findTwsxFiles(inputDir);
23
+ const generatedCssFiles = [];
24
+
25
+ // Generate CSS from JS files
23
26
  for (const filePath of twsxFiles) {
24
27
  try {
25
28
  const styleModule = await import(
@@ -30,6 +33,7 @@ async function buildTwsx(inputDir, outputDir) {
30
33
  const fileName = path.basename(filePath).replace(/\.js$/, ".css");
31
34
  const cssFilePath = path.join(outputDir, fileName);
32
35
  fs.writeFileSync(cssFilePath, css);
36
+ generatedCssFiles.push(fileName);
33
37
  } catch (err) {
34
38
  console.error(
35
39
  `[webpack-twsx] Error importing or processing ${filePath}:`,
@@ -37,6 +41,22 @@ async function buildTwsx(inputDir, outputDir) {
37
41
  );
38
42
  }
39
43
  }
44
+
45
+ // Clean up orphaned CSS files
46
+ if (fs.existsSync(outputDir)) {
47
+ const existingCssFiles = fs.readdirSync(outputDir).filter((file) => {
48
+ return file.startsWith("twsx.") && file.endsWith(".css");
49
+ });
50
+
51
+ if (Array.isArray(existingCssFiles) && Array.isArray(generatedCssFiles)) {
52
+ for (const cssFile of existingCssFiles) {
53
+ if (!generatedCssFiles.includes(cssFile)) {
54
+ const cssFilePath = path.join(outputDir, cssFile);
55
+ fs.unlinkSync(cssFilePath);
56
+ }
57
+ }
58
+ }
59
+ }
40
60
  } catch (err) {
41
61
  console.error("[webpack-twsx] Error scanning for twsx files:", err);
42
62
  }