某些Tailwind样式在Next.js中无法用于生产

出于某种原因,一些样式似乎不适用于 Netlify 上托管的生产版本。这似乎只发生在单个组件上。它是一个位于./layout/FormLayout.tsx(不知道这是否会改变任何东西)的包装器。这是包装器:

const FormLayout: React.FC<FormLayout> = ({ children, title, description }) => {
    return (
        <div className="w-screen mt-32 flex flex-col items-center justify-center">
            <div className="p-6 flex flex-col items-center justify-center">
                <h2 className="text-4xl font-semibold text-blue-400">
                    {title}
                </h2>
                {description && (
                    <h6 className="mt-4 text-md font-medium">{description}</h6>
                )}
                <div className="mt-12 w-max">{children}</div>
            </div>
        </div>
    )
}

它在这里使用:

const Register: React.FC<RegisterProps> = () => {
    return (
        <FormLayout title="Register" description="Register with your email.">
            {/* form stuff. styles do work in here */}
        </FormLayout>
    )
}

下面是一些配置文件:

顺风配置:

module.exports = {
    purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
    darkMode: 'class',
    theme: {
        extend: {},
    },
    variants: {
        extend: {},
    },
    plugins: [],
}

postcss 配置:

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

这是正在发生的事情的图形示例:

对于我的构建命令,我使用next build && next export和 Netlify 部署/out目录。

所有代码都在这里通过github

回答

对于将来看到这一点的任何人,只需将purge数组中任何新文件夹的路径添加到 tailwind 配置中,如下所示:

module.exports = {
    purge: [
        './pages/**/*.{js,ts,jsx,tsx}',
        './components/**/*.{js,ts,jsx,tsx}',
        './layout/**/*.{js,ts,jsx,tsx}',
        './helpers/**/*.{js,ts,jsx,tsx}',
        // Add more here
    ],
    darkMode: 'class',
    theme: {
        extend: {},
    },
    variants: {
        extend: {},
    },
    plugins: [],
}


以上是某些Tailwind样式在Next.js中无法用于生产的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>