Skip to content

Commit 5d6b1d3

Browse files
committed
[devtools] initialize tailwind
1 parent 5d159b9 commit 5d6b1d3

File tree

9 files changed

+645
-210
lines changed

9 files changed

+645
-210
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This code runs on the browser.
2+
// The options.target is provided from shadow-portal.tsx file.
3+
function insertIntoTarget(element, options) {
4+
var root =
5+
options.target ||
6+
document.querySelector('script[data-nextjs-dev-overlay] > nextjs-portal')
7+
.shadowRoot
8+
9+
root.insertBefore(element, root.firstChild)
10+
}
11+
12+
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
"@storybook/test-runner": "0.21.0",
182182
"@swc/core": "1.11.24",
183183
"@swc/types": "0.1.7",
184+
"@tailwindcss/postcss": "4.1.9",
184185
"@taskr/clear": "1.1.0",
185186
"@taskr/esnext": "1.1.0",
186187
"@types/amphtml-validator": "1.0.0",
@@ -250,6 +251,7 @@
250251
"cross-env": "6.0.3",
251252
"cross-spawn": "7.0.3",
252253
"crypto-browserify": "3.12.0",
254+
"css-loader": "7.1.2",
253255
"css.escape": "1.5.1",
254256
"cssnano-preset-default": "7.0.6",
255257
"data-uri-to-buffer": "3.0.1",
@@ -292,6 +294,7 @@
292294
"path-to-regexp": "6.1.0",
293295
"picomatch": "4.0.1",
294296
"postcss-flexbugs-fixes": "5.0.2",
297+
"postcss-loader": "8.1.1",
295298
"postcss-modules-extract-imports": "3.0.0",
296299
"postcss-modules-local-by-default": "4.2.0",
297300
"postcss-modules-scope": "3.0.0",
@@ -326,7 +329,9 @@
326329
"string-hash": "1.1.3",
327330
"string_decoder": "1.3.0",
328331
"strip-ansi": "6.0.0",
332+
"style-loader": "4.0.0",
329333
"superstruct": "1.0.3",
334+
"tailwindcss": "4.1.8",
330335
"tar": "6.1.15",
331336
"taskr": "1.1.0",
332337
"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: 10 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,13 @@ 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+
// The target is passed to the next-devtools-inject-tailwind.js file which runs on the browser.
42+
// x-ref: https://webpack.js.org/loaders/style-loader/#lazystyletag
43+
tailwindCss.use({
44+
target: shadowNode.current,
45+
})
3646
}
3747
forceUpdate({})
3848
}, [])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import 'tailwindcss';

0 commit comments

Comments
 (0)