Skip to content

Commit 25e28a9

Browse files
authored
fix(tailwindcss): avoid unnecessary rebuild when running dev (#3702)
1 parent 008c9bb commit 25e28a9

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

.changeset/happy-bulldogs-raise.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@modern-js/plugin-tailwindcss': patch
3+
---
4+
5+
fix(tailwindcss): avoid unnecessary rebuild when running dev
6+
7+
fix(tailwindcss): 修复 dev 模式下不必要的重新构建

packages/cli/plugin-tailwind/src/cli.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ export const getRandomTwConfigFileName = (internalDirectory: string) => {
3030
);
3131
};
3232

33+
function getDefaultContent(appDirectory: string) {
34+
const defaultContent = [
35+
'./src/**/*.js',
36+
'./src/**/*.jsx',
37+
'./src/**/*.ts',
38+
'./src/**/*.tsx',
39+
];
40+
41+
// Only add storybook and html config when they exist
42+
// Otherwise, it will cause an unnecessary rebuild
43+
if (fs.existsSync(path.join(appDirectory, 'storybook'))) {
44+
defaultContent.push('./storybook/**/*');
45+
}
46+
if (fs.existsSync(path.join(appDirectory, 'config/html'))) {
47+
defaultContent.push(
48+
'./config/html/**/*.html',
49+
'./config/html/**/*.ejs',
50+
'./config/html/**/*.hbs',
51+
);
52+
}
53+
54+
return defaultContent;
55+
}
56+
3357
export default (
3458
{ pluginName } = {
3559
pluginName: '@modern-js/plugin-tailwindcss',
@@ -50,18 +74,7 @@ export default (
5074
const haveTwinMacro = await checkTwinMacroExist(appDirectory);
5175
const tailwindPath = getTailwindPath(appDirectory);
5276
const tailwindVersion = getTailwindVersion(appDirectory);
53-
54-
const defaultContent = [
55-
'./config/html/**/*.html',
56-
'./config/html/**/*.ejs',
57-
'./config/html/**/*.hbs',
58-
'./src/**/*.js',
59-
'./src/**/*.jsx',
60-
'./src/**/*.ts',
61-
'./src/**/*.tsx',
62-
// about storybook
63-
'./storybook/**/*',
64-
];
77+
const defaultContent = getDefaultContent(appDirectory);
6578

6679
return {
6780
prepare() {

0 commit comments

Comments
 (0)