从尾风中的库中添加插件

发布于 2025-01-23 08:25:12 字数 1621 浏览 3 评论 0原文

我正在使用React,NX,Tailwind来创建一个带有多个配置

MonorePo

的 每个项目一个配置 一个扩展每个LIB项目配置的插件。

我目前有以下内容:

root :: tailwind.config(基本样式)

module.exports = {
  content: [],
  theme: {
    extend: {
      colors: {
        '27313B': '#27313B',
      },
    },
  },
  plugins: [],
};

project :: tailwdind.config(扩展了root并呼叫插件)

const { createGlobPatternsForDependencies } = require('@nrwl/react/tailwind');
const { join } = require('path');

module.exports = {
  content: [
    join(__dirname, 'src/**/!(*.stories|*.spec).{ts,tsx,html}'),
    ...createGlobPatternsForDependencies(__dirname),
  ],
  presets: [require(join(__dirname, '../../tailwind.config'))],
  theme: {
    extend: {},
  },
  plugins: [require(join(__dirname, '../../libs//tailwind.plugin'))],
};

lib:lib: :tailwind.plugin

const plugin = require('tailwindcss/plugin');

module.exports = {
  plugins: [
    plugin(
      function ({ matchUtilities, theme }) {
        matchUtilities(
          {
            colors: (value) => ({
              colors: value,
            }),
          },
          { values: theme('colors') }
        );
      },
      {
        theme: {
          extend: {
            colors: {
              F00: '#f00',
            },
          },
        },
      }
    ),
  ],
};

可悲的是,插件永远无法使用,

这样做 < div className = {'text-27313b'}> asdasd</div> 显示好的颜色,但 < div className = {'text-f00'}> asdasd</div> 我不

配置错误吗?

I am using react, nx, tailwind to create a monorepo with multiple config

What I would like to achieve is

one config for the whole repo
one config per project
one plugin that extend the project config on each lib.

I currently have this :

root::tailwind.config (base styles)

module.exports = {
  content: [],
  theme: {
    extend: {
      colors: {
        '27313B': '#27313B',
      },
    },
  },
  plugins: [],
};

project::tailwdind.config (extends the root and call for a plugin)

const { createGlobPatternsForDependencies } = require('@nrwl/react/tailwind');
const { join } = require('path');

module.exports = {
  content: [
    join(__dirname, 'src/**/!(*.stories|*.spec).{ts,tsx,html}'),
    ...createGlobPatternsForDependencies(__dirname),
  ],
  presets: [require(join(__dirname, '../../tailwind.config'))],
  theme: {
    extend: {},
  },
  plugins: [require(join(__dirname, '../../libs//tailwind.plugin'))],
};

lib::tailwind.plugin

const plugin = require('tailwindcss/plugin');

module.exports = {
  plugins: [
    plugin(
      function ({ matchUtilities, theme }) {
        matchUtilities(
          {
            colors: (value) => ({
              colors: value,
            }),
          },
          { values: theme('colors') }
        );
      },
      {
        theme: {
          extend: {
            colors: {
              F00: '#f00',
            },
          },
        },
      }
    ),
  ],
};

Sadly, the plugin never work,

doing
<div className={'text-27313B'}>asdasd</div>
show the good color but
<div className={'text-F00'}>asdasd</div>
dont

I am configuring it wrong ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薯片软お妹 2025-01-30 08:25:12

你尝试这个

 module.exports = {
      content: [],
      theme: {
        extend: {
          colors: {
            27313B: '#27313B',
          },
        },
      },
      plugins: [],
    };

you try this

 module.exports = {
      content: [],
      theme: {
        extend: {
          colors: {
            27313B: '#27313B',
          },
        },
      },
      plugins: [],
    };
云醉月微眠 2025-01-30 08:25:12

好的,我复制了错误的粘贴...

module.exports = plugin(
  function ({ matchUtilities, theme }) {
    matchUtilities(
      {
        colors: (value) => ({
          colors: value,
        }),
      },
      { values: theme('colors') }
    );
  },
  {
    theme: {
      extend: {
        colors: {
          F00: '#f00',
        },
      },
    },
  }
);

工作。

我正在导出一个插件:plugin(),而不是只是插件()

ok I copy pasted wrong...

module.exports = plugin(
  function ({ matchUtilities, theme }) {
    matchUtilities(
      {
        colors: (value) => ({
          colors: value,
        }),
      },
      { values: theme('colors') }
    );
  },
  {
    theme: {
      extend: {
        colors: {
          F00: '#f00',
        },
      },
    },
  }
);

works.

I was exporting a plugin : plugin() instead of just plugin()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文