Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not generate tailwind.config.js in dist/ #4

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/TailwindCSSRspackPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mkdir, writeFile } from 'node:fs/promises';
import { mkdtemp, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { pathToFileURL } from 'node:url';

Expand Down Expand Up @@ -184,13 +185,14 @@ class TailwindRspackPluginImpl {
: // biome-ignore lint/style/noNonNullAssertion: should have context
path.resolve(this.compiler.options.context!, this.options.config);

const outputDir = path.resolve(
// biome-ignore lint/style/noNonNullAssertion: should have `output.path`
this.compiler.options.output.path!,
'.rsbuild',
entryName,
);
await mkdir(outputDir, { recursive: true });
const outputDir = DEBUG
? path.resolve(
// biome-ignore lint/style/noNonNullAssertion: should have `output.path`
this.compiler.options.output.path!,
'.rsbuild',
entryName,
)
: await mkdtemp(path.join(tmpdir(), entryName));

const configPath = path.resolve(outputDir, 'tailwind.config.mjs');

Expand Down Expand Up @@ -220,3 +222,14 @@ function collectModules(
entryModules.add(module.resource);
}
}

const DEBUG = (function isDebug() {
if (!process.env.DEBUG) {
return false;
}

const values = process.env.DEBUG.toLocaleLowerCase().split(',');
return ['rsbuild', 'rsbuild:tailwind', 'rsbuild:*', '*'].some((key) =>
values.includes(key),
);
})();
16 changes: 15 additions & 1 deletion test/basic/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dirname } from 'node:path';
import { existsSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test } from '@playwright/test';
import { createRsbuild } from '@rsbuild/core';
Expand Down Expand Up @@ -64,3 +65,16 @@ test('should build with tailwind utilities', async ({ page }) => {

await server.close();
});

test('should not generate tailwind.config.js in dist/', async () => {
const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: {
plugins: [pluginTailwindCSS()],
},
});

await rsbuild.build();

expect(existsSync(resolve(__dirname, './dist/.rsbuild'))).toBeFalsy();
});