Skip to content

Commit bba3d9d

Browse files
committed
[devtools] initialize tailwind
1 parent 737d319 commit bba3d9d

File tree

11 files changed

+965
-211
lines changed

11 files changed

+965
-211
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
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function insertIntoTarget(element, options) {
2+
var root =
3+
options.target ||
4+
document.querySelector('script[data-nextjs-dev-overlay] > nextjs-portal')
5+
.shadowRoot
6+
7+
root.insertBefore(element, root.firstChild)
8+
}
9+
10+
module.exports = insertIntoTarget

packages/next/next-devtools.webpack-config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ module.exports = ({ dev, ...rest }) => {
8888
module: {
8989
rules: [
9090
{ test: /\.m?js$/, loader: `source-map-loader`, enforce: `pre` },
91+
// TODO: minify
92+
{
93+
test: /tailwind\.css$/,
94+
use: [
95+
{
96+
loader: 'style-loader',
97+
options: {
98+
injectType: 'lazyStyleTag',
99+
insert: require.resolve('./next-devtools-inject-tailwind.js'),
100+
},
101+
},
102+
'css-loader',
103+
'postcss-loader',
104+
],
105+
},
91106
{
92107
test: /\.(ts|tsx)$/,
93108
exclude: [/node_modules/],

packages/next/package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@
8989
"ncc-compiled": "taskr ncc",
9090
"storybook": "BROWSER=none storybook dev -p 6006",
9191
"build-storybook": "storybook build",
92-
"test-storybook": "test-storybook"
92+
"test-storybook": "test-storybook",
93+
"tw-build": "tailwindcss --input ./src/next-devtools/dev-overlay/tailwind.input.css --output ./src/next-devtools/dev-overlay/styles/tailwind.output.css",
94+
"tw-watch": "pnpm tw-build --watch=always"
9395
},
9496
"taskr": {
9597
"requires": [
@@ -181,6 +183,8 @@
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",
187+
"@tailwindcss/postcss": "4.1.9",
184188
"@taskr/clear": "1.1.0",
185189
"@taskr/esnext": "1.1.0",
186190
"@types/amphtml-validator": "1.0.0",
@@ -250,6 +254,7 @@
250254
"cross-env": "6.0.3",
251255
"cross-spawn": "7.0.3",
252256
"crypto-browserify": "3.12.0",
257+
"css-loader": "7.1.2",
253258
"css.escape": "1.5.1",
254259
"cssnano-preset-default": "7.0.6",
255260
"data-uri-to-buffer": "3.0.1",
@@ -292,6 +297,7 @@
292297
"path-to-regexp": "6.1.0",
293298
"picomatch": "4.0.1",
294299
"postcss-flexbugs-fixes": "5.0.2",
300+
"postcss-loader": "8.1.1",
295301
"postcss-modules-extract-imports": "3.0.0",
296302
"postcss-modules-local-by-default": "4.2.0",
297303
"postcss-modules-scope": "3.0.0",
@@ -326,7 +332,9 @@
326332
"string-hash": "1.1.3",
327333
"string_decoder": "1.3.0",
328334
"strip-ansi": "6.0.0",
335+
"style-loader": "4.0.0",
329336
"superstruct": "1.0.3",
337+
"tailwindcss": "4.1.8",
330338
"tar": "6.1.15",
331339
"taskr": "1.1.0",
332340
"terser": "5.27.0",

packages/next/postcss.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
plugins: {
3+
'@tailwindcss/postcss': {},
4+
},
5+
}

packages/next/src/compiled/babel-packages/packages-bundle.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/next/src/compiled/postcss-preset-env/index.cjs

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

packages/next/src/next-devtools/dev-overlay/components/shadow-portal.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import * as React from 'react'
22
import { createPortal } from 'react-dom'
33
import { STORAGE_KEY_THEME } from '../shared'
44

5+
// @ts-expect-error - CSS file missing type declaration
6+
import tailwindCss from '../tailwind.css'
7+
58
export function ShadowPortal({ children }: { children: React.ReactNode }) {
69
let portalNode = React.useRef<HTMLElement | null>(null)
710
let shadowNode = React.useRef<ShadowRoot | null>(null)
@@ -33,6 +36,12 @@ export function ShadowPortal({ children }: { children: React.ReactNode }) {
3336
// createa React Root in getInitialProps but don't clean it up like test/integration/app-tree/pages/_app.tsx
3437
if (portalNode.current.shadowRoot === null) {
3538
shadowNode.current = portalNode.current.attachShadow({ mode: 'open' })
39+
40+
// Injecting Tailwind to the Shadow DOM with Webpack style-loader.
41+
// x-ref: https://webpack.js.org/loaders/style-loader/#lazystyletag
42+
tailwindCss.use({
43+
target: shadowNode.current,
44+
})
3645
}
3746
forceUpdate({})
3847
}, [])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import 'tailwindcss';

packages/next/types/global.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ declare module '*.module.scss' {
4343
export default classes
4444
}
4545

46+
declare module '*.css?raw' {
47+
const content: string
48+
export default content
49+
}
50+
4651
// We implement the behavior of `import 'server-only'` and `import 'client-only'` on the compiler level
4752
// and thus don't require having them installed as dependencies.
4853
// By default it works fine with typescript, because (surprisingly) TSC *doesn't check side-effecting imports*.

0 commit comments

Comments
 (0)