tailwind-to-style 2.8.3 → 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 +38 -27
- package/dist/index.browser.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.esm.js +1 -1
- package/lib/build-twsx.js +0 -1
- package/package.json +1 -1
- package/plugins/vite-twsx.js +6 -9
- package/plugins/webpack-twsx.js +1 -15
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.
|
|
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.
|
|
496
|
-
4.
|
|
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 '
|
|
502
|
+
import twsxPlugin from 'tailwind-to-style/plugins/vite-twsx';
|
|
503
503
|
|
|
504
504
|
export default {
|
|
505
505
|
plugins: [
|
|
506
506
|
twsxPlugin({
|
|
507
|
-
|
|
508
|
-
|
|
507
|
+
inputDir: 'src',
|
|
508
|
+
outputDir: 'src/styles'
|
|
509
509
|
})
|
|
510
510
|
]
|
|
511
511
|
};
|
|
512
512
|
```
|
|
513
513
|
|
|
514
|
-
After build,
|
|
515
|
-
Import in
|
|
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
|
-
//
|
|
518
|
-
import '
|
|
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 '
|
|
526
|
+
import TwsxPlugin from 'tailwind-to-style/plugins/webpack-twsx';
|
|
526
527
|
|
|
527
528
|
module.exports = {
|
|
528
529
|
plugins: [
|
|
529
530
|
new TwsxPlugin({
|
|
530
|
-
|
|
531
|
-
|
|
531
|
+
inputDir: 'src',
|
|
532
|
+
outputDir: 'src/styles'
|
|
532
533
|
})
|
|
533
534
|
]
|
|
534
535
|
};
|
|
535
536
|
```
|
|
536
537
|
|
|
537
|
-
After build,
|
|
538
|
-
Import in
|
|
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
|
-
//
|
|
541
|
-
import '
|
|
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
|
|
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
|
|
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.
|
|
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
|
-
|
|
567
|
+
|
|
568
|
+
3. After running, individual CSS files will be available in the output directory (default: `src/styles/`):
|
|
569
|
+
|
|
564
570
|
```
|
|
565
|
-
|
|
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 '
|
|
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
|
```
|
package/dist/index.browser.js
CHANGED
package/dist/index.cjs
CHANGED
package/dist/index.esm.js
CHANGED
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
package/plugins/vite-twsx.js
CHANGED
|
@@ -21,7 +21,7 @@ async function buildTwsx(inputDir, outputDir) {
|
|
|
21
21
|
try {
|
|
22
22
|
const twsxFiles = findTwsxFiles(inputDir);
|
|
23
23
|
const generatedCssFiles = [];
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
// Generate CSS from JS files
|
|
26
26
|
for (const filePath of twsxFiles) {
|
|
27
27
|
try {
|
|
@@ -41,20 +41,17 @@ async function buildTwsx(inputDir, outputDir) {
|
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
// Clean up orphaned CSS files
|
|
46
46
|
if (fs.existsSync(outputDir)) {
|
|
47
|
-
const existingCssFiles = fs
|
|
48
|
-
.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
console.log(`[vite-twsx] Generated ${generatedCssFiles.length} CSS files:`, generatedCssFiles);
|
|
52
|
-
|
|
47
|
+
const existingCssFiles = fs
|
|
48
|
+
.readdirSync(outputDir)
|
|
49
|
+
.filter((file) => file.startsWith("twsx.") && file.endsWith(".css"));
|
|
50
|
+
|
|
53
51
|
for (const cssFile of existingCssFiles) {
|
|
54
52
|
if (!generatedCssFiles.includes(cssFile)) {
|
|
55
53
|
const cssFilePath = path.join(outputDir, cssFile);
|
|
56
54
|
fs.unlinkSync(cssFilePath);
|
|
57
|
-
console.log(`[vite-twsx] Removed orphaned CSS: ${cssFilePath}`);
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
57
|
}
|
package/plugins/webpack-twsx.js
CHANGED
|
@@ -34,7 +34,6 @@ async function buildTwsx(inputDir, outputDir) {
|
|
|
34
34
|
const cssFilePath = path.join(outputDir, fileName);
|
|
35
35
|
fs.writeFileSync(cssFilePath, css);
|
|
36
36
|
generatedCssFiles.push(fileName);
|
|
37
|
-
console.log(`[webpack-twsx] CSS written to ${cssFilePath}`);
|
|
38
37
|
} catch (err) {
|
|
39
38
|
console.error(
|
|
40
39
|
`[webpack-twsx] Error importing or processing ${filePath}:`,
|
|
@@ -49,24 +48,11 @@ async function buildTwsx(inputDir, outputDir) {
|
|
|
49
48
|
return file.startsWith("twsx.") && file.endsWith(".css");
|
|
50
49
|
});
|
|
51
50
|
|
|
52
|
-
if (
|
|
53
|
-
Array.isArray(existingCssFiles) &&
|
|
54
|
-
Array.isArray(generatedCssFiles)
|
|
55
|
-
) {
|
|
56
|
-
console.log(
|
|
57
|
-
`[webpack-twsx] Found ${existingCssFiles.length} existing CSS files:`,
|
|
58
|
-
existingCssFiles
|
|
59
|
-
);
|
|
60
|
-
console.log(
|
|
61
|
-
`[webpack-twsx] Generated ${generatedCssFiles.length} CSS files:`,
|
|
62
|
-
generatedCssFiles
|
|
63
|
-
);
|
|
64
|
-
|
|
51
|
+
if (Array.isArray(existingCssFiles) && Array.isArray(generatedCssFiles)) {
|
|
65
52
|
for (const cssFile of existingCssFiles) {
|
|
66
53
|
if (!generatedCssFiles.includes(cssFile)) {
|
|
67
54
|
const cssFilePath = path.join(outputDir, cssFile);
|
|
68
55
|
fs.unlinkSync(cssFilePath);
|
|
69
|
-
console.log(`[webpack-twsx] Removed orphaned CSS: ${cssFilePath}`);
|
|
70
56
|
}
|
|
71
57
|
}
|
|
72
58
|
}
|