【发布时间】:2022-01-12 06:59:17
【问题描述】:
我有一个如下所示的 tailwind.config.js 文件:
const colors = require('tailwindcss/colors');
const plugin = require('tailwindcss/plugin');
module.exports = {
mode: 'jit',
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html', './src/css/safelist.txt'],
theme: {
extend: {
animation: ['animate-pulse', 'animate-spin', 'visually-hidden'],
boxShadow: {
DEFAULT: '0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px 0 rgba(0, 0, 0, 0.02)',
md: '0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.02)',
lg: '0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.01)',
xl: '0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 10px 10px -5px rgba(0, 0, 0, 0.01)',
},
colors: {
gray: colors.blueGray,
'light-blue': colors.sky,
red: colors.rose,
'navy-blue': '#273A72',
'cobalt': '#1F6DA4',
'light-blue':'#A6CEE3',
'light-grey':'#E8E8E8',
'bright-red': "#FF0000",
'pastel-green': "#53BB78"
},
outline: {
blue: '2px solid rgba(0, 112, 244, 0.5)',
},
fontFamily: {
inter: ['Inter', 'sans-serif'],
'Roboto': ['Roboto', 'sans-serif']
},
fontSize: {
xs: ['0.75rem', { lineHeight: '1.5' }],
sm: ['0.875rem', { lineHeight: '1.5715' }],
base: ['1rem', { lineHeight: '1.5', letterSpacing: '-0.01em' }],
lg: ['1.125rem', { lineHeight: '1.5', letterSpacing: '-0.01em' }],
xl: ['1.25rem', { lineHeight: '1.5', letterSpacing: '-0.01em' }],
"2xl": ['1.5rem', { lineHeight: '1.5', letterSpacing: '-0.01em' }],
},
screens: {
xs: '480px',
},
borderWidth: {
3: '3px',
},
minWidth: {
36: '9rem',
44: '11rem',
56: '14rem',
60: '15rem',
72: '18rem',
80: '20rem',
},
maxWidth: {
'8xl': '88rem',
'9xl': '96rem',
},
zIndex: {
60: '60',
},
},
},
plugins: [
// eslint-disable-next-line global-require
require('@tailwindcss/forms'),
// add custom variant for expanding sidebar
plugin(({ addVariant, e }) => {
addVariant('sidebar-expanded', ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => `.sidebar-expanded .${e(`sidebar-expanded${separator}${className}`)}`);
});
}),
],
};
在节点开发服务器中运行时,一切正常。但是,使用此文件构建会使所有内容变为空白并引发
Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
在控制台中。
当我将 tailwind 配置文件更改为
const colors = require('tailwindcss/colors');
const plugin = require('tailwindcss/plugin');
module.exports = {
mode: 'jit',
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html', './src/css/safelist.txt'],
theme: {
extend: {
animation: ['animate-pulse', 'animate-spin', 'visually-hidden'],
boxShadow: {
DEFAULT: '0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px 0 rgba(0, 0, 0, 0.02)',
md: '0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.02)',
lg: '0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.01)',
xl: '0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 10px 10px -5px rgba(0, 0, 0, 0.01)',
},
colors: {
gray: colors.blueGray,
'light-blue': colors.sky,
red: colors.rose,
},
outline: {
blue: '2px solid rgba(0, 112, 244, 0.5)',
},
fontFamily: {
inter: ['Inter', 'sans-serif'],
'Roboto': ['Roboto', 'sans-serif']
},
fontSize: {
xs: ['0.75rem', { lineHeight: '1.5' }],
sm: ['0.875rem', { lineHeight: '1.5715' }],
base: ['1rem', { lineHeight: '1.5', letterSpacing: '-0.01em' }],
lg: ['1.125rem', { lineHeight: '1.5', letterSpacing: '-0.01em' }],
xl: ['1.25rem', { lineHeight: '1.5', letterSpacing: '-0.01em' }],
"2xl": ['1.5rem', { lineHeight: '1.5', letterSpacing: '-0.01em' }],
},
screens: {
xs: '480px',
},
borderWidth: {
3: '3px',
},
minWidth: {
36: '9rem',
44: '11rem',
56: '14rem',
60: '15rem',
72: '18rem',
80: '20rem',
},
maxWidth: {
'8xl': '88rem',
'9xl': '96rem',
},
zIndex: {
60: '60',
},
},
},
plugins: [
// eslint-disable-next-line global-require
require('@tailwindcss/forms'),
// add custom variant for expanding sidebar
plugin(({ addVariant, e }) => {
addVariant('sidebar-expanded', ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => `.sidebar-expanded .${e(`sidebar-expanded${separator}${className}`)}`);
});
}),
],
};
(除了自定义颜色外,其他都一样)
自定义颜色显然消失了,但突然一切正常,并且生产版本渲染正常。
有没有办法解决这个问题(修复被定义为带有颜色的工作生产版本)?
【问题讨论】:
-
您使用的是哪个版本的 Tailwind?
-
package.json中是^2.2.19
-
据我所知,我们使用的是 3.0.13
-
您的双引号自定义颜色是否可能存在问题,例如("#FF0000")?
-
很遗憾,将双引号改为单引号并不能解决问题
标签: reactjs tailwind-css