Skip to content

Commit cba7a99

Browse files
authored
feat: follow the community agreement and explicitly use tailwindcss (#30)
1 parent 5a53399 commit cba7a99

File tree

8 files changed

+32
-112
lines changed

8 files changed

+32
-112
lines changed

.changeset/cool-laws-walk.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@umijs/tnf': patch
3+
---
4+
5+
feat: Follow the community agreement and explicitly use tailwindcss

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Config is loaded from `.tnfrc.ts` by default.
5959
- `externals: Record<string, string>`: An object that maps package names to their corresponding paths.
6060
- `less: { modifyVars?: Record<string, string>; globalVars?: Record<string, string>; math?: 'always' | 'strict' | 'parens-division' | 'parens' | 'strict-legacy' | number; sourceMap?: any; plugins?: (string | [string, Record<string, any>])[];}`: The configuration passed to lessLoader.
6161
- `router: { defaultPreload?: 'intent' | 'render' | 'viewport'; defaultPreloadDelay?: number; devtool?: { options?: { initialIsOpen?: boolean; position?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right' }; } | false }`: The router configuration.
62+
- `tailwindcss: boolean`: Turn on/off tailwindcss. Need to be used in conjunction with `src/tailwind.css` and `tailwind.config.js`.
6263

6364
## FAQ
6465

examples/tailwindcss/.tnfrc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ export default {
22
router: {
33
defaultPreload: 'intent',
44
},
5-
tailwindcss: {},
5+
tailwindcss: true,
66
};

examples/tailwindcss/src/tailwind.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
content: [
3+
"./src/pages/**/*.{js,ts,jsx,tsx}",
4+
"./src/components/**/*.{js,ts,jsx,tsx}"
5+
]
6+
}

src/config.ts

+1-79
Original file line numberDiff line numberDiff line change
@@ -47,85 +47,7 @@ const ConfigSchema = z.object({
4747
.optional(),
4848
})
4949
.optional(),
50-
tailwindcss: z
51-
.union([
52-
z.object({
53-
content: z
54-
.union([
55-
z.array(
56-
z.union([
57-
z.string(),
58-
z.object({
59-
raw: z.string(),
60-
extension: z.string().optional(),
61-
}),
62-
]),
63-
),
64-
z.object({
65-
files: z.array(
66-
z.union([
67-
z.string(),
68-
z.object({
69-
raw: z.string(),
70-
extension: z.string().optional(),
71-
}),
72-
]),
73-
),
74-
relative: z.boolean().optional(),
75-
extract: z
76-
.union([
77-
z.function().args(z.string()).returns(z.array(z.string())),
78-
z.record(
79-
z.string(),
80-
z.function().args(z.string()).returns(z.array(z.string())),
81-
),
82-
])
83-
.optional(),
84-
transform: z
85-
.union([
86-
z.function().args(z.string()).returns(z.string()),
87-
z.record(
88-
z.string(),
89-
z.function().args(z.string()).returns(z.string()),
90-
),
91-
])
92-
.optional(),
93-
}),
94-
])
95-
.optional(),
96-
important: z.union([z.boolean(), z.string()]).optional(),
97-
prefix: z.string().optional(),
98-
separator: z.string().optional(),
99-
safelist: z
100-
.array(
101-
z.union([
102-
z.string(),
103-
z.object({
104-
pattern: z.instanceof(RegExp),
105-
variants: z.array(z.string()).optional(),
106-
}),
107-
]),
108-
)
109-
.optional(),
110-
darkMode: z
111-
.union([
112-
z.literal('media'),
113-
z.literal('class'),
114-
z.tuple([z.literal('class'), z.string()]),
115-
z.literal('selector'),
116-
z.tuple([z.literal('selector'), z.string()]),
117-
z.tuple([
118-
z.literal('variant'),
119-
z.union([z.string(), z.array(z.string())]),
120-
]),
121-
])
122-
.optional(),
123-
theme: z.record(z.string(), z.any()).optional(),
124-
plugins: z.array(z.function()).optional(),
125-
}),
126-
z.record(z.string(), z.any()),
127-
])
128-
.optional(),
50+
tailwindcss: z.boolean().optional(),
12951
});
13052

13153
export type Config = z.infer<typeof ConfigSchema>;

src/fishkit/tailwindcss.ts

+15-31
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ interface TailwindConfig {
2222
interface GenerateTailwindcssOpts {
2323
cwd: string;
2424
tmpPath: string;
25-
config: Config['tailwindcss'];
2625
mode: 'development' | 'production';
2726
}
2827

@@ -69,44 +68,29 @@ function getTailwindBinPath(opts: { cwd: string }): string {
6968
export async function generateTailwindcss(
7069
opts: GenerateTailwindcssOpts,
7170
): Promise<string> {
72-
const { cwd, tmpPath, config, mode } = opts;
71+
const { cwd, tmpPath, mode } = opts;
7372
const rootPath = path.join(tmpPath, 'tailwindcss');
7473

7574
// 设置文件路径
7675
const paths = {
77-
input: path.join(rootPath, 'tailwindDirectives.css'),
76+
input: path.join(cwd, 'src/tailwind.css'),
7877
output: path.join(rootPath, 'tailwind.css'),
79-
config: path.join(rootPath, 'tailwind.config.js'),
78+
config: path.join(cwd, 'tailwind.config.js'),
8079
};
8180

82-
// 默认 Tailwind 配置
83-
const defaultConfig: TailwindConfig = {
84-
content: [
85-
'./src/pages/**/*.{js,ts,jsx,tsx}',
86-
'./src/components/**/*.{js,ts,jsx,tsx}',
87-
],
88-
};
89-
90-
const mergedConfig = { ...defaultConfig, ...config };
91-
92-
// 确保目录存在
93-
fs.mkdirpSync(path.dirname(paths.input));
94-
95-
// 写入 Tailwind 指令文件
96-
fs.writeFileSync(
97-
paths.input,
98-
`
99-
@tailwind base;
100-
@tailwind components;
101-
@tailwind utilities;
102-
`.trim(),
103-
);
81+
if (!fs.existsSync(paths.input)) {
82+
console.log(
83+
'Enabling feature tailwindcss requires input file src/tailwind.css',
84+
);
85+
return '';
86+
}
10487

105-
// 写入配置文件
106-
fs.writeFileSync(
107-
paths.config,
108-
`export default ${JSON.stringify(mergedConfig, null, 2)}`,
109-
);
88+
if (!fs.existsSync(paths.config)) {
89+
console.log(
90+
'Enabling feature tailwindcss requires config file tailwind.config.js',
91+
);
92+
return '';
93+
}
11094

11195
// 生成 CSS 文件
11296
await generateFile({

src/sync.ts

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export async function sync(opts: SyncOptions) {
6565
tailwindcssPath = await generateTailwindcss({
6666
cwd,
6767
tmpPath,
68-
config: config?.tailwindcss,
6968
mode,
7069
});
7170
}

0 commit comments

Comments
 (0)