我有一个正在构建的next.js站点,它使用下面的特定文本,
const defaultTheme = require('tailwindcss/defaultTheme')
module.exports = {
theme: {
extend: {
fontFamily: {
sans: ['SFMono-Regular', 'Menlo', ...defaultTheme.fontFamily.sans],
},
colors: {
// indigo: '#7D00FF',
blue: '#51B1E8',
red: '#FF0E00',
},
},
},
plugins: [
require('@tailwindcss/ui'),
]
}由于某些原因,文本样式在部署到Vercel时会被清除。这是清除css配置。
module.exports = {
plugins: [
"postcss-import",
"tailwindcss",
"autoprefixer"
]
};
const purgecss = [
"@fullhuman/postcss-purgecss",
{
content: [
'./pages/**/**/*.{js,jsx,ts,tsx}',
'./pages/**/*.{js,jsx,ts,tsx}',
'./pages/*.{js,jsx,ts,tsx}',
'./components/**/**/*.{js,jsx,ts,tsx}',
'./components/**/*.{js,jsx,ts,tsx}',
'./components/*.{js,jsx,ts,tsx}',
],
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || []
}
];
module.exports = {
plugins: [
"postcss-import",
"tailwindcss",
"autoprefixer",
...(process.env.NODE_ENV === "production" ? [purgecss] : [])
]
};怎么一回事?
提前谢谢你,
发布于 2020-10-09 09:40:19
我可以通过在设置中将html和body添加到safelist来解决这个问题。
const purgecss = require('@fullhuman/postcss-purgecss')({
// Specify the paths to all of the template files in your project
content: [
// './src/**/*.html',
'./pages/**/*.vue',
'./layouts/**/*.vue',
'./components/**/*.vue'
],
safelist: ['html', 'body'],
// Include any special characters you're using in this regular expression
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
})注意您使用的是哪个版本的purgecss (请查看package.json):从whitelistPatterns到safelist有一个更改,我花了一些时间才弄清楚
发布于 2021-03-19 01:06:53
我在我的Vue项目中设置了这个:
module.exports = {
content: [
"./src/**/*.vue",
],
safelist: [
"body",
"html",
"img",
"a",
"g-image",
"g-image--lazy",
"g-image--loaded",
/-(leave|enter|appear)(|-(to|from|active))$/,
/^(?!(|.*?:)cursor-move).+-move$/,
/^router-link(|-exact)-active$/,
/data-v-.*/,
],
extractors: [
{
extractor: (content) => content.match(/[A-z0-9-:\\/]+/g),
extensions: ["vue"],
},
],
}根据您使用的PurgeCSS版本(我的版本是:v3.1.3),safelist用于排除模式,在较旧的版本中,您可能必须使用whitelist。
https://stackoverflow.com/questions/63870891
复制相似问题