Tailwindcss nextjs JIT模式编译报错
Tailwindcss nextjs JIT mode compile error
我们正在用 tailwindcss 做一个项目,在客户想要一个“像素完美”的设计之前它一直很顺利,这意味着我们需要以像素而不是 rem 来设置每一个东西。因此,我没有添加 1 个 gajillon 类,如 h-1px、h-2px ... h-100px 等。我决定启用 JIT 模式并改用 h-[100px]。
问题是编译器一直在编译,即使我什么也没做改变,并且继续这样做,即使我停止了开发服务器,一个进程在端口 3000 上 运行(我无法再次启动服务器,直到我阻止它)。
所以..问题是如何停止这个重新编译的无限循环
我正在使用:
顺风 2.1.2
tailwindcss/jit 0.1.18
我的 tw 配置目前是这样的,可能有什么东西触发了循环:
const colors = require("tailwindcss/colors");
const defaultTheme = require("tailwindcss/defaultTheme");
module.exports = {
important: true,
mode: "jit",
//content: ["./src/**/*.{js,ts,jsx,tsx,liquid}"],
purge: {
enabled: false,
content: [
"./src/components/**/*.{js,ts,jsx,tsx,html}",
"./src/pages/**/*.{js,ts,jsx,tsx,html}",
"./src/components/*.{js,ts,jsx,tsx,html}",
"./src/pages/*.{js,ts,jsx,tsx,html}",
"./src/**/*.{js,ts,jsx,tsx,html}",
"./src/*.{js,ts,jsx,tsx,html}",
"./**/*.{js,ts,jsx,tsx,html}",
"./*.{js,ts,jsx,tsx,html}",
],
options: {
safelist: {
deep: [/bg$/, /col$/, /row$/, /text$/],
greedy: [/bg$/, /col$/, /row$/, /text$/],
},
},
},
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
opacity: { 13: "0.13" },
boxShadow: {
head: "0 0 6px 0 rgba(0, 0, 0, 0.36)",
search: "0 9px 34px 0 rgba(0, 0, 0, 0.19)",
},
gridTemplateRows: {
// Simple 8 row grid
"8-em": "repeat(8, minmax(0, 5em))",
8: "repeat(8, minmax(0, 1fr))",
},
backgroundImage: {
"gradient-radial": "radial-gradient(var(--gradient-color-stops))",
},
fontFamily: {
sans: ["Stolzl", ...defaultTheme.fontFamily.sans],
},
fontSize: {
"2.5xl": "1.6rem",
0.8: "0.8rem",
xxs: "0.6rem",
micro: "0.4rem",
nano: "0.2rem",
},
zIndex: {
0: 0,
10: 10,
20: 20,
30: 30,
40: 40,
50: 50,
25: 25,
50: 50,
60: 60,
75: 75,
100: 100,
200: 200,
auto: "auto",
},
colors: {
// old primary blue #005a94
// old lightblue #f4f7fd
//TODO change colors
primaryLightBlue: "#f1f7fb",
primaryBlue: process.env.NEXT_PUBLIC_PRIMARY || "#1579B9",
primaryYellow: process.env.NEXT_PUBLIC_ACCENT || "#FDC607",
},
radialGradientColors: {
// defaults to {}
"blue-blue": ["#0171BA", "#005a94"],
"lb-lb": ["#3776dd", "#215dc0"],
},
animation: {
spin3d: "spin3d 6s linear infinite ",
},
keyframes: {
spin3d: {
"0%": {
transform: "perspective(1000px) rotateY(0deg)",
filter: "brightness(100%)",
},
"25%": { filter: "brightness(60%)" },
"50%": {
filter: "brightness(100%)",
},
"75%": { filter: "brightness(60%)" },
"100% ": {
transform: "perspective(1000px) rotateY(360deg)",
filter: "brightness(100%)",
},
},
},
},
},
plugins: [
require("tailwindcss-gradients"),
require("@tailwindcss/line-clamp"),
function ({ addComponents }) {
addComponents({
".container": {
maxWidth: "100%",
//640
"@screen sm": {
maxWidth: "640px",
},
//768
"@screen md": {
maxWidth: "768px",
},
//1024
"@screen lg": {
maxWidth: "1024px",
},
//1280
"@screen xl": {
maxWidth: "1280px",
},
//1280
"@screen 2xl": {
maxWidth: "1280px",
},
},
".container2": {
maxWidth: "100%",
//640
"@screen sm": {
maxWidth: "640px",
},
//768
"@screen md": {
maxWidth: "640px",
},
//1024
"@screen lg": {
maxWidth: "768px",
},
//1280
"@screen xl": {
maxWidth: "1118px",
},
//1280
"@screen 2xl": {
maxWidth: "1118px",
},
},
});
},
],
variants: {
display: ["group-hover"],
extend: {
backgroundColor: ["odd"],
borderColor: ["odd", "even", "active"],
borderOpacity: ["odd", "even", "active"],
borderWidth: ["odd", "even", "active"],
borderStyle: ["odd", "even", "active"],
display: ["disabled", "responsive"],
opacity: ["disabled"],
cursor: ["disabled", "hover"],
backgroundColor: ["disabled"],
borderWidth: ["hover,focus"],
transform: ["hover", "focus", "group-hover"],
scale: ["hover", "focus", "group-hover"],
width: ["hover", "group-hover"],
height: ["hover", "group-hover"],
padding: ["hover", "focus"],
},
},
};
我解决了,有同样问题的人
首先我必须卸载@tailwindcss/jit 依赖项,因为它包含在 tailwind css v2.2.7+
中
然后我必须配置 postcss 以使用 'tailwindcss' 而不是 '@tailwindcss/jit',
然后我更改了我的脚本以在顺风构建脚本之前包含 TAILWIND_MODE=watch,并在末尾添加 --watch
"tailwind:build": "TAILWIND_MODE=watch tailwind build -i ./src/styles/tailwind.css -o ./src/styles/styles.css --watch ",
一切都开始工作了,没有无限循环!
我们正在用 tailwindcss 做一个项目,在客户想要一个“像素完美”的设计之前它一直很顺利,这意味着我们需要以像素而不是 rem 来设置每一个东西。因此,我没有添加 1 个 gajillon 类,如 h-1px、h-2px ... h-100px 等。我决定启用 JIT 模式并改用 h-[100px]。 问题是编译器一直在编译,即使我什么也没做改变,并且继续这样做,即使我停止了开发服务器,一个进程在端口 3000 上 运行(我无法再次启动服务器,直到我阻止它)。 所以..问题是如何停止这个重新编译的无限循环
我正在使用: 顺风 2.1.2 tailwindcss/jit 0.1.18
我的 tw 配置目前是这样的,可能有什么东西触发了循环:
const colors = require("tailwindcss/colors");
const defaultTheme = require("tailwindcss/defaultTheme");
module.exports = {
important: true,
mode: "jit",
//content: ["./src/**/*.{js,ts,jsx,tsx,liquid}"],
purge: {
enabled: false,
content: [
"./src/components/**/*.{js,ts,jsx,tsx,html}",
"./src/pages/**/*.{js,ts,jsx,tsx,html}",
"./src/components/*.{js,ts,jsx,tsx,html}",
"./src/pages/*.{js,ts,jsx,tsx,html}",
"./src/**/*.{js,ts,jsx,tsx,html}",
"./src/*.{js,ts,jsx,tsx,html}",
"./**/*.{js,ts,jsx,tsx,html}",
"./*.{js,ts,jsx,tsx,html}",
],
options: {
safelist: {
deep: [/bg$/, /col$/, /row$/, /text$/],
greedy: [/bg$/, /col$/, /row$/, /text$/],
},
},
},
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
opacity: { 13: "0.13" },
boxShadow: {
head: "0 0 6px 0 rgba(0, 0, 0, 0.36)",
search: "0 9px 34px 0 rgba(0, 0, 0, 0.19)",
},
gridTemplateRows: {
// Simple 8 row grid
"8-em": "repeat(8, minmax(0, 5em))",
8: "repeat(8, minmax(0, 1fr))",
},
backgroundImage: {
"gradient-radial": "radial-gradient(var(--gradient-color-stops))",
},
fontFamily: {
sans: ["Stolzl", ...defaultTheme.fontFamily.sans],
},
fontSize: {
"2.5xl": "1.6rem",
0.8: "0.8rem",
xxs: "0.6rem",
micro: "0.4rem",
nano: "0.2rem",
},
zIndex: {
0: 0,
10: 10,
20: 20,
30: 30,
40: 40,
50: 50,
25: 25,
50: 50,
60: 60,
75: 75,
100: 100,
200: 200,
auto: "auto",
},
colors: {
// old primary blue #005a94
// old lightblue #f4f7fd
//TODO change colors
primaryLightBlue: "#f1f7fb",
primaryBlue: process.env.NEXT_PUBLIC_PRIMARY || "#1579B9",
primaryYellow: process.env.NEXT_PUBLIC_ACCENT || "#FDC607",
},
radialGradientColors: {
// defaults to {}
"blue-blue": ["#0171BA", "#005a94"],
"lb-lb": ["#3776dd", "#215dc0"],
},
animation: {
spin3d: "spin3d 6s linear infinite ",
},
keyframes: {
spin3d: {
"0%": {
transform: "perspective(1000px) rotateY(0deg)",
filter: "brightness(100%)",
},
"25%": { filter: "brightness(60%)" },
"50%": {
filter: "brightness(100%)",
},
"75%": { filter: "brightness(60%)" },
"100% ": {
transform: "perspective(1000px) rotateY(360deg)",
filter: "brightness(100%)",
},
},
},
},
},
plugins: [
require("tailwindcss-gradients"),
require("@tailwindcss/line-clamp"),
function ({ addComponents }) {
addComponents({
".container": {
maxWidth: "100%",
//640
"@screen sm": {
maxWidth: "640px",
},
//768
"@screen md": {
maxWidth: "768px",
},
//1024
"@screen lg": {
maxWidth: "1024px",
},
//1280
"@screen xl": {
maxWidth: "1280px",
},
//1280
"@screen 2xl": {
maxWidth: "1280px",
},
},
".container2": {
maxWidth: "100%",
//640
"@screen sm": {
maxWidth: "640px",
},
//768
"@screen md": {
maxWidth: "640px",
},
//1024
"@screen lg": {
maxWidth: "768px",
},
//1280
"@screen xl": {
maxWidth: "1118px",
},
//1280
"@screen 2xl": {
maxWidth: "1118px",
},
},
});
},
],
variants: {
display: ["group-hover"],
extend: {
backgroundColor: ["odd"],
borderColor: ["odd", "even", "active"],
borderOpacity: ["odd", "even", "active"],
borderWidth: ["odd", "even", "active"],
borderStyle: ["odd", "even", "active"],
display: ["disabled", "responsive"],
opacity: ["disabled"],
cursor: ["disabled", "hover"],
backgroundColor: ["disabled"],
borderWidth: ["hover,focus"],
transform: ["hover", "focus", "group-hover"],
scale: ["hover", "focus", "group-hover"],
width: ["hover", "group-hover"],
height: ["hover", "group-hover"],
padding: ["hover", "focus"],
},
},
};
我解决了,有同样问题的人
首先我必须卸载@tailwindcss/jit 依赖项,因为它包含在 tailwind css v2.2.7+
中然后我必须配置 postcss 以使用 'tailwindcss' 而不是 '@tailwindcss/jit',
然后我更改了我的脚本以在顺风构建脚本之前包含 TAILWIND_MODE=watch,并在末尾添加 --watch
"tailwind:build": "TAILWIND_MODE=watch tailwind build -i ./src/styles/tailwind.css -o ./src/styles/styles.css --watch ",
一切都开始工作了,没有无限循环!