-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support tailwindcss v3.1.x and v3.2.y (#21)
### Summary Support Tailwind CSS v3.1 and Tailwind CSS v3.2. --- ### Details Since Tailwind CSS support using ESM configuration in V3.3, we need to use CJS configuration before that. As mentioned in #7 (comment), we use `readFile` + `require.resolve` to get the version of `tailwindcss/package.json`. - If `satisfies(version, ^3.3.0)`, we will generate ESM configuration to support both ESM and CJS. - Else, we generate CJS configuration. --- ### Test plan We setup two new entries in the testing matrix - tailwindcss v3.1.0 with Ubuntu - tailwindcss v3.1.0 with Windows As you can see, the test is failing at [0e05c6a](0e05c6a). And after the fix is landed in [e783415](e783415), the test for old tailwindcss is passing. --- ### Related links close: #18 - Tailwind CSS v3.3: - https://github.com/tailwindlabs/tailwindcss/releases/tag/v3.3.0 - tailwindlabs/tailwindcss#10785 - Tailwind CSS v3.2 - https://github.com/tailwindlabs/tailwindcss/releases/tag/v3.2.0 - Tailwind CSS v3.1 - https://github.com/tailwindlabs/tailwindcss/releases/tag/v3.1.0
- Loading branch information
Showing
11 changed files
with
240 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
2 changes: 1 addition & 1 deletion
2
test/basic/tailwind.config.js → test/cjs/config/tailwind.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/** @type {import('tailwindcss').Config} */ | ||
export default {}; | ||
module.exports = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { dirname, resolve } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { expect, test } from '@playwright/test'; | ||
import { createRsbuild } from '@rsbuild/core'; | ||
import { pluginTailwindCSS } from '../../src'; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
test('should build with relative config', async ({ page }) => { | ||
const rsbuild = await createRsbuild({ | ||
cwd: __dirname, | ||
rsbuildConfig: { | ||
plugins: [ | ||
pluginTailwindCSS({ | ||
config: './config/tailwind.config.js', | ||
}), | ||
], | ||
}, | ||
}); | ||
|
||
await rsbuild.build(); | ||
const { server, urls } = await rsbuild.preview(); | ||
|
||
await page.goto(urls[0]); | ||
|
||
const display = await page.evaluate(() => { | ||
const el = document.getElementById('test'); | ||
|
||
if (!el) { | ||
throw new Error('#test not found'); | ||
} | ||
|
||
return window.getComputedStyle(el).getPropertyValue('display'); | ||
}); | ||
|
||
expect(display).toBe('flex'); | ||
|
||
await server.close(); | ||
}); | ||
|
||
test('should build with absolute config', async ({ page }) => { | ||
const rsbuild = await createRsbuild({ | ||
cwd: __dirname, | ||
rsbuildConfig: { | ||
plugins: [ | ||
pluginTailwindCSS({ | ||
config: resolve(__dirname, './config/tailwind.config.js'), | ||
}), | ||
], | ||
}, | ||
}); | ||
|
||
await rsbuild.build(); | ||
const { server, urls } = await rsbuild.preview(); | ||
|
||
await page.goto(urls[0]); | ||
|
||
const display = await page.evaluate(() => { | ||
const el = document.getElementById('test'); | ||
|
||
if (!el) { | ||
throw new Error('#test not found'); | ||
} | ||
|
||
return window.getComputedStyle(el).getPropertyValue('display'); | ||
}); | ||
|
||
expect(display).toBe('flex'); | ||
|
||
await server.close(); | ||
}); | ||
|
||
test('should build without tailwind.config.js', async ({ page }) => { | ||
const rsbuild = await createRsbuild({ | ||
cwd: __dirname, | ||
rsbuildConfig: { | ||
plugins: [pluginTailwindCSS()], | ||
}, | ||
}); | ||
|
||
await rsbuild.build(); | ||
const { server, urls } = await rsbuild.preview(); | ||
|
||
await page.goto(urls[0]); | ||
|
||
const display = await page.evaluate(() => { | ||
const el = document.getElementById('test'); | ||
|
||
if (!el) { | ||
throw new Error('#test not found'); | ||
} | ||
|
||
return window.getComputedStyle(el).getPropertyValue('display'); | ||
}); | ||
|
||
expect(display).toBe('flex'); | ||
|
||
await server.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'tailwindcss/utilities.css'; | ||
|
||
function className() { | ||
return 'flex'; | ||
} | ||
|
||
const root = document.getElementById('root'); | ||
const element = document.createElement('div'); | ||
element.id = 'test'; | ||
element.className = className(); | ||
root.appendChild(element); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.