简体   繁体   English

NextJS:TailwindCSS 在生产中不起作用

[英]NextJS: TailwindCSS not working in production

I'm using NextJS, TailwindCSS and Typescript.我正在使用 NextJS、TailwindCSS 和 Typescript。 When running in development, everything works as expected, but when running in production, no tailwindcss classes are applied.在开发中运行时,一切都按预期工作,但在生产中运行时,没有应用 tailwindcss 类。 Here is a link to the repo: https://github.com/Capsule-app/next .这是回购的链接: https://github.com/Capsule-app/next

This problems occurred because of Purge.此问题是由于清除而发生的。 Please check the official page请查看官方页面

Few possible way to fixed this issues.解决此问题的可能方法很少。 Option A (Quick & Dirty Plus Lazy): In tailwind.config.js file try purge: false选项 A(Quick & Dirty Plus Lazy):在tailwind.config.js文件中尝试purge: false

Option B: If you are using purge: ["./pages/**/*.{js,jsx,ts,tsx}", "./components/**/*.{js,ts,jsx,tsx}"], Or If you have custom css class or third-party lib class then follow Safelisting with `install @fullhuman/postcss-purgecss first then try选项 B:如果您使用purge: ["./pages/**/*.{js,jsx,ts,tsx}", "./components/**/*.{js,ts,jsx,tsx}"],或者如果您有自定义 css class 或第三方库 class 然后按照安全列表使用 `install @fullhuman/postcss-purgecss 先然后尝试

// postcss.config.js

module.exports = {
   plugins: {
      tailwindcss: {},
      autoprefixer: {},
      ...(process.env.NODE_ENV === 'production'
         ? {
              '@fullhuman/postcss-purgecss': {
                 // added sections folder and changed extension to jsx
                 content: ['./src/components/**/*.jsx', './src/pages/**/*.js'],
                 defaultExtractor: content =>
                    content.match(/[\w-/:]+(?<!:)/g) || [],
              },
           }
         : {}),
   },
}`

Note: Each solution depend on it's context.注意:每个解决方案都取决于它的上下文。 I request to you read official docs carefully.我要求您仔细阅读官方文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM