tailwind-to-style 2.8.1 → 2.8.2
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/dist/index.browser.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.esm.js +1 -1
- package/lib/build-twsx.js +42 -23
- package/package.json +1 -1
- package/plugins/vite-twsx.js +44 -31
- package/plugins/webpack-twsx.js +47 -35
package/dist/index.browser.js
CHANGED
package/dist/index.cjs
CHANGED
package/dist/index.esm.js
CHANGED
package/lib/build-twsx.js
CHANGED
|
@@ -3,39 +3,58 @@ import path from "path";
|
|
|
3
3
|
import { pathToFileURL } from "url";
|
|
4
4
|
import { twsx } from "tailwind-to-style";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
const
|
|
6
|
+
function findTwsxFiles(dir, files = []) {
|
|
7
|
+
const items = fs.readdirSync(dir);
|
|
8
|
+
for (const item of items) {
|
|
9
|
+
const fullPath = path.join(dir, item);
|
|
10
|
+
const stat = fs.statSync(fullPath);
|
|
11
|
+
if (stat.isDirectory()) {
|
|
12
|
+
findTwsxFiles(fullPath, files);
|
|
13
|
+
} else if (item.startsWith("twsx.") && item.endsWith(".js")) {
|
|
14
|
+
files.push(fullPath);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return files;
|
|
18
|
+
}
|
|
8
19
|
|
|
9
|
-
async function buildTwsx() {
|
|
10
|
-
let allCss = "";
|
|
20
|
+
async function buildTwsx(inputDir, outputDir) {
|
|
11
21
|
try {
|
|
12
|
-
const
|
|
13
|
-
for (const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const twsxFiles = findTwsxFiles(inputDir);
|
|
23
|
+
for (const filePath of twsxFiles) {
|
|
24
|
+
try {
|
|
25
|
+
const styleModule = await import(
|
|
26
|
+
pathToFileURL(filePath).href + `?update=${Date.now()}`
|
|
27
|
+
);
|
|
28
|
+
const styleObj = styleModule.default || styleModule;
|
|
29
|
+
const css = twsx(styleObj, { inject: false });
|
|
30
|
+
const fileName = path.basename(filePath).replace(/\.js$/, ".css");
|
|
31
|
+
const cssFilePath = path.join(outputDir, fileName);
|
|
32
|
+
fs.writeFileSync(cssFilePath, css);
|
|
33
|
+
console.log(`[build-twsx] CSS written to ${cssFilePath}`);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.error(
|
|
36
|
+
`[build-twsx] Error importing or processing ${filePath}:`,
|
|
37
|
+
err
|
|
38
|
+
);
|
|
25
39
|
}
|
|
26
40
|
}
|
|
27
41
|
} catch (err) {
|
|
28
|
-
console.error(
|
|
42
|
+
console.error("[build-twsx] Error scanning for twsx files:", err);
|
|
29
43
|
}
|
|
30
|
-
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const inputDir =
|
|
47
|
+
process.env.TWSX_INPUT_DIR || path.resolve(process.cwd(), "src");
|
|
48
|
+
const outputDir =
|
|
49
|
+
process.env.TWSX_OUTPUT_DIR || path.resolve(process.cwd(), "src/styles");
|
|
50
|
+
if (!fs.existsSync(outputDir)) {
|
|
51
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
31
52
|
}
|
|
32
53
|
|
|
33
54
|
(async () => {
|
|
34
55
|
try {
|
|
35
|
-
|
|
36
|
-
fs.writeFileSync(cssFile, allCss);
|
|
37
|
-
console.log(`[build-twsx] CSS written to ${cssFile}`);
|
|
56
|
+
await buildTwsx(inputDir, outputDir);
|
|
38
57
|
} catch (err) {
|
|
39
|
-
console.error(
|
|
58
|
+
console.error("[build-twsx] Error writing CSS:", err);
|
|
40
59
|
}
|
|
41
60
|
})();
|
package/package.json
CHANGED
package/plugins/vite-twsx.js
CHANGED
|
@@ -1,58 +1,71 @@
|
|
|
1
|
-
|
|
2
1
|
import fs from "fs";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import { pathToFileURL } from "url";
|
|
5
4
|
import { twsx } from "tailwind-to-style";
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
function findTwsxFiles(dir, files = []) {
|
|
7
|
+
const items = fs.readdirSync(dir);
|
|
8
|
+
for (const item of items) {
|
|
9
|
+
const fullPath = path.join(dir, item);
|
|
10
|
+
const stat = fs.statSync(fullPath);
|
|
11
|
+
if (stat.isDirectory()) {
|
|
12
|
+
findTwsxFiles(fullPath, files);
|
|
13
|
+
} else if (item.startsWith("twsx.") && item.endsWith(".js")) {
|
|
14
|
+
files.push(fullPath);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return files;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function buildTwsx(inputDir, outputDir) {
|
|
9
21
|
try {
|
|
10
|
-
const
|
|
11
|
-
for (const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const twsxFiles = findTwsxFiles(inputDir);
|
|
23
|
+
for (const filePath of twsxFiles) {
|
|
24
|
+
try {
|
|
25
|
+
const styleModule = await import(
|
|
26
|
+
pathToFileURL(filePath).href + `?update=${Date.now()}`
|
|
27
|
+
);
|
|
28
|
+
const styleObj = styleModule.default || styleModule;
|
|
29
|
+
const css = twsx(styleObj, { inject: false });
|
|
30
|
+
const fileName = path.basename(filePath).replace(/\.js$/, ".css");
|
|
31
|
+
const cssFilePath = path.join(outputDir, fileName);
|
|
32
|
+
fs.writeFileSync(cssFilePath, css);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error(
|
|
35
|
+
`[vite-twsx] Error importing or processing ${filePath}:`,
|
|
36
|
+
err
|
|
37
|
+
);
|
|
23
38
|
}
|
|
24
39
|
}
|
|
25
40
|
} catch (err) {
|
|
26
|
-
console.error(
|
|
41
|
+
console.error("[vite-twsx] Error scanning for twsx files:", err);
|
|
27
42
|
}
|
|
28
|
-
return
|
|
43
|
+
return null;
|
|
29
44
|
}
|
|
30
45
|
|
|
31
46
|
export default function twsxPlugin(options = {}) {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
process.cwd(),
|
|
35
|
-
|
|
36
|
-
)
|
|
47
|
+
const inputDir = options.inputDir || path.resolve(process.cwd(), "src");
|
|
48
|
+
const outputDir =
|
|
49
|
+
options.outputDir || path.resolve(process.cwd(), "src/styles");
|
|
50
|
+
|
|
51
|
+
if (!fs.existsSync(outputDir)) {
|
|
52
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
53
|
+
}
|
|
37
54
|
|
|
38
55
|
return {
|
|
39
56
|
name: "vite-twsx",
|
|
40
57
|
async buildStart() {
|
|
41
58
|
try {
|
|
42
|
-
|
|
43
|
-
fs.writeFileSync(cssFile, allCss);
|
|
44
|
-
console.log(`[vite-twsx] CSS written to ${cssFile}`);
|
|
59
|
+
await buildTwsx(inputDir, outputDir);
|
|
45
60
|
} catch (err) {
|
|
46
|
-
console.error(
|
|
61
|
+
console.error("[vite-twsx] Error writing CSS:", err);
|
|
47
62
|
}
|
|
48
63
|
},
|
|
49
64
|
async handleHotUpdate() {
|
|
50
65
|
try {
|
|
51
|
-
|
|
52
|
-
fs.writeFileSync(cssFile, allCss);
|
|
53
|
-
console.log(`[vite-twsx] CSS written to ${cssFile}`);
|
|
66
|
+
await buildTwsx(inputDir, outputDir);
|
|
54
67
|
} catch (err) {
|
|
55
|
-
console.error(
|
|
68
|
+
console.error("[vite-twsx] Error updating CSS:", err);
|
|
56
69
|
}
|
|
57
70
|
},
|
|
58
71
|
};
|
package/plugins/webpack-twsx.js
CHANGED
|
@@ -3,56 +3,68 @@ import path from "path";
|
|
|
3
3
|
import { pathToFileURL } from "url";
|
|
4
4
|
import { twsx } from "tailwind-to-style";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
function findTwsxFiles(dir, files = []) {
|
|
7
|
+
const items = fs.readdirSync(dir);
|
|
8
|
+
for (const item of items) {
|
|
9
|
+
const fullPath = path.join(dir, item);
|
|
10
|
+
const stat = fs.statSync(fullPath);
|
|
11
|
+
if (stat.isDirectory()) {
|
|
12
|
+
findTwsxFiles(fullPath, files);
|
|
13
|
+
} else if (item.startsWith("twsx.") && item.endsWith(".js")) {
|
|
14
|
+
files.push(fullPath);
|
|
15
|
+
}
|
|
9
16
|
}
|
|
17
|
+
return files;
|
|
18
|
+
}
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
20
|
+
async function buildTwsx(inputDir, outputDir) {
|
|
21
|
+
try {
|
|
22
|
+
const twsxFiles = findTwsxFiles(inputDir);
|
|
23
|
+
for (const filePath of twsxFiles) {
|
|
24
|
+
try {
|
|
25
|
+
const styleModule = await import(
|
|
26
|
+
pathToFileURL(filePath).href + `?update=${Date.now()}`
|
|
27
|
+
);
|
|
28
|
+
const styleObj = styleModule.default || styleModule;
|
|
29
|
+
const css = twsx(styleObj, { inject: false });
|
|
30
|
+
const fileName = path.basename(filePath).replace(/\.js$/, ".css");
|
|
31
|
+
const cssFilePath = path.join(outputDir, fileName);
|
|
32
|
+
fs.writeFileSync(cssFilePath, css);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error(
|
|
35
|
+
`[webpack-twsx] Error importing or processing ${filePath}:`,
|
|
36
|
+
err
|
|
37
|
+
);
|
|
28
38
|
}
|
|
29
|
-
} catch (err) {
|
|
30
|
-
console.error('[webpack-twsx] Error reading twsxDir:', err);
|
|
31
39
|
}
|
|
32
|
-
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.error("[webpack-twsx] Error scanning for twsx files:", err);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class TwsxPlugin {
|
|
46
|
+
constructor(options = {}) {
|
|
47
|
+
this.inputDir = options.inputDir || path.resolve(process.cwd(), "src");
|
|
48
|
+
this.outputDir =
|
|
49
|
+
options.outputDir || path.resolve(process.cwd(), "src/styles");
|
|
50
|
+
if (!fs.existsSync(this.outputDir)) {
|
|
51
|
+
fs.mkdirSync(this.outputDir, { recursive: true });
|
|
52
|
+
}
|
|
33
53
|
}
|
|
34
54
|
|
|
35
55
|
apply(compiler) {
|
|
36
|
-
const cssFile = path.resolve(
|
|
37
|
-
process.cwd(),
|
|
38
|
-
"node_modules/tailwind-to-style/twsx.css"
|
|
39
|
-
);
|
|
40
56
|
compiler.hooks.beforeCompile.tapPromise("TwsxPlugin", async () => {
|
|
41
57
|
try {
|
|
42
|
-
|
|
43
|
-
fs.writeFileSync(cssFile, allCss);
|
|
44
|
-
console.log(`[webpack-twsx] CSS written to ${cssFile}`);
|
|
58
|
+
await buildTwsx(this.inputDir, this.outputDir);
|
|
45
59
|
} catch (err) {
|
|
46
|
-
console.error(
|
|
60
|
+
console.error("[webpack-twsx] Error writing CSS:", err);
|
|
47
61
|
}
|
|
48
62
|
});
|
|
49
63
|
compiler.hooks.watchRun.tapPromise("TwsxPlugin", async () => {
|
|
50
64
|
try {
|
|
51
|
-
|
|
52
|
-
fs.writeFileSync(cssFile, allCss);
|
|
53
|
-
console.log(`[webpack-twsx] CSS written to ${cssFile}`);
|
|
65
|
+
await buildTwsx(this.inputDir, this.outputDir);
|
|
54
66
|
} catch (err) {
|
|
55
|
-
console.error(
|
|
67
|
+
console.error("[webpack-twsx] Error updating CSS:", err);
|
|
56
68
|
}
|
|
57
69
|
});
|
|
58
70
|
}
|