【问题标题】:Nextjs/postcss css variables not available in production (Zeit)Nextjs/postcss css 变量在生产中不可用 (Zeit)
【发布时间】:2020-07-16 08:12:30
【问题描述】:

我有一系列定义暗模式主题的变量。 在本地运行应用程序时,这些变量已完美加载。

这是 CSS 检查器:

dark-mode {
  --color-bg-bg: #100818;
  --color-bg-primary: #100818;
  --color-bg-secondary: #1e1528;
  --color-bg-almost-primary: rgba(15,8,24,0.8);
  --color-bg-light: #0e0917;
}

但如果我为生产构建应用程序或将其部署在 Zeist 中,则这些变量不可用。

我认为启用custom-properties 功能可以解决问题,但事实并非如此。这是我的 postcss 配置文件:

module.exports = {
  plugins: [
    'tailwindcss',
    process.env.NODE_ENV === 'production'
      ? [
        '@fullhuman/postcss-purgecss',
        {
          content: [
            './pages/**/*.{js,jsx,ts,tsx}',
            './components/**/*.{js,jsx,ts,tsx}',
          ],
          defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],
          features: {
            'custom-properties': true,
          },
        },
      ]
      : undefined,
    'postcss-preset-env',
  ],
};

有什么想法吗?谢谢!

【问题讨论】:

    标签: deployment next.js postcss css-variables vercel


    【解决方案1】:

    我不了解 zeit,但是在开发版和生产版中都可以从 .module.css 文件中访问在全局 css 中声明的变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-17
      • 1970-01-01
      • 2020-08-03
      • 2020-10-04
      • 1970-01-01
      • 2018-04-25
      • 2016-04-08
      • 2020-04-07
      相关资源
      最近更新 更多