Skip to content

Commit 7a2b6ec

Browse files
committed
[devtools] initialize tailwind
1 parent a075f9c commit 7a2b6ec

File tree

9 files changed

+677
-163
lines changed

9 files changed

+677
-163
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ packages/next/src/bundles/webpack/packages/*.runtime.js
1515
packages/next/src/bundles/webpack/packages/lazy-compilation-*.js
1616
packages/next/wasm/@next
1717
packages/next/errors.json
18+
packages/next/**/tailwind.output.css
1819

1920
.github/actions/next-stats-action/.work
2021
.changeset/*.md

packages/next/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@
8989
"ncc-compiled": "taskr ncc",
9090
"storybook": "storybook dev -p 6006",
9191
"build-storybook": "storybook build",
92-
"test-storybook": "test-storybook"
92+
"test-storybook": "test-storybook",
93+
"build-tw": "tailwindcss --input ./src/client/components/react-dev-overlay/ui/styles/tailwind.input.css --output ./src/client/components/react-dev-overlay/ui/styles/tailwind.output.css --minify",
94+
"watch-tw": "pnpm build-tw --watch"
9395
},
9496
"taskr": {
9597
"requires": [
@@ -181,6 +183,7 @@
181183
"@storybook/test-runner": "0.21.0",
182184
"@swc/core": "1.11.24",
183185
"@swc/types": "0.1.7",
186+
"@tailwindcss/cli": "4.1.8",
184187
"@taskr/clear": "1.1.0",
185188
"@taskr/esnext": "1.1.0",
186189
"@types/amphtml-validator": "1.0.0",
@@ -327,6 +330,7 @@
327330
"string_decoder": "1.3.0",
328331
"strip-ansi": "6.0.0",
329332
"superstruct": "1.0.3",
333+
"tailwindcss": "4.1.8",
330334
"tar": "6.1.15",
331335
"taskr": "1.1.0",
332336
"terser": "5.27.0",

packages/next/src/client/components/react-dev-overlay/ui/dev-overlay.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { RenderError } from './container/runtime-error/render-error'
1111
import { DarkTheme } from './styles/dark-theme'
1212
import { useDevToolsScale } from './components/errors/dev-tools-indicator/dev-tools-info/preferences'
1313
import type { HydrationErrorState } from '../pages/hydration-error-state'
14+
import { Tailwind } from './styles/tailwind'
1415

1516
export function DevOverlay({
1617
state,
@@ -29,6 +30,7 @@ export function DevOverlay({
2930
<Colors />
3031
<ComponentStyles />
3132
<DarkTheme />
33+
<Tailwind />
3234

3335
<RenderError state={state} isAppDir={true}>
3436
{({ runtimeErrors, totalErrorCount }) => {

packages/next/src/client/components/react-dev-overlay/ui/styles/tailwind.gen.tsx

Lines changed: 10 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import 'tailwindcss';

packages/next/src/client/components/react-dev-overlay/ui/styles/tailwind.output.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Tailwind } from './tailwind.gen'

packages/next/taskfile.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2829,7 +2829,13 @@ export async function diagnostics(task, opts) {
28292829

28302830
export async function build(task, opts) {
28312831
await task.serial(
2832-
['precompile', 'compile', 'check_error_codes', 'generate_types'],
2832+
[
2833+
'inject_tailwind_styles',
2834+
'precompile',
2835+
'compile',
2836+
'check_error_codes',
2837+
'generate_types',
2838+
],
28332839
opts
28342840
)
28352841
}
@@ -2871,6 +2877,39 @@ export async function check_error_codes(task, opts) {
28712877
}
28722878
}
28732879

2880+
export async function inject_tailwind_styles() {
2881+
// Generate the production build of tailwind css file.
2882+
await execa.command('pnpm build-tw', {
2883+
stdio: 'inherit',
2884+
})
2885+
2886+
const stylesDir = 'src/client/components/react-dev-overlay/ui/styles'
2887+
2888+
const css = await fs.readFile(
2889+
join(__dirname, stylesDir, 'tailwind.output.css'),
2890+
'utf8'
2891+
)
2892+
2893+
// Escape `export` keyword because `export function` is pre-processed
2894+
// as `exports.function` when taskfile.js is being transformed.
2895+
const exportKeyword = 'export'
2896+
const source = `// This file is generated by taskfile.js "inject_tailwind_styles" task.
2897+
${exportKeyword} function Tailwind() {
2898+
return (
2899+
<style>
2900+
{${JSON.stringify(css)}}
2901+
</style>
2902+
)
2903+
}
2904+
`
2905+
2906+
await fs.writeFile(
2907+
join(__dirname, stylesDir, 'tailwind.gen.tsx'),
2908+
source,
2909+
'utf-8'
2910+
)
2911+
}
2912+
28742913
export default async function (task) {
28752914
const opts = { dev: true }
28762915
await task.clear('dist')

0 commit comments

Comments
 (0)