使用 Vue3 和 postcss 的 Fullcalendar 自定义 css

发布于 2025-01-11 20:56:29 字数 1466 浏览 0 评论 0原文

我正在使用 vue3 的 fullcalendar。我想更改全日历中按钮和文本的颜色。

vue 版本

"vue": "^3.2.26",

我收到错误

语法错误:错误:PostCSS 插件 postcss-custom-properties 需要 PostCSS 8。

我按照 fullcalendar 文档中提到的步骤操作。

fullcalendar-vars.css

:root {
  --fc-border-color: green;
  --fc-button-text-color: #ff0000;
}

我已经安装了以下软件包

"postcss": "^8.4.7",
"postcss-calc": "^8.2.4",
"postcss-custom-properties": "^12.1.4",
"postcss-loader": "^6.2.1",

在根目录添加了 postcss.config.js

module.exports = {
    plugins: [
      require('postcss-custom-properties')({
        preserve: false, // completely reduce all css vars
        importFrom: [
          'client/fullcalendar-vars.css' // look here for the new values
        ]
      }),
      require('postcss-calc')
    ]
  }

和我的 vue.config.js 如下

const path = require("path");
module.exports = {
  pages: {
    index: {
      entry: "./client/main.js",
    },
  },
  outputDir: path.resolve(__dirname, "./client/dist"),
};

另外我我想知道,我需要对 vue.config.js 进行任何更改吗?

I am using fullcalendar with vue3. I want to change change colors for button and text in fullcalendar.

vue version

"vue": "^3.2.26",

I am getting error

Syntax Error: Error: PostCSS plugin postcss-custom-properties requires
PostCSS 8.

I am following steps mentioned in fullcalendar documentation.

fullcalendar-vars.css

:root {
  --fc-border-color: green;
  --fc-button-text-color: #ff0000;
}

I have installed following packages

"postcss": "^8.4.7",
"postcss-calc": "^8.2.4",
"postcss-custom-properties": "^12.1.4",
"postcss-loader": "^6.2.1",

Added postcss.config.js at root

module.exports = {
    plugins: [
      require('postcss-custom-properties')({
        preserve: false, // completely reduce all css vars
        importFrom: [
          'client/fullcalendar-vars.css' // look here for the new values
        ]
      }),
      require('postcss-calc')
    ]
  }

And my vue.config.js as follow

const path = require("path");
module.exports = {
  pages: {
    index: {
      entry: "./client/main.js",
    },
  },
  outputDir: path.resolve(__dirname, "./client/dist"),
};

Also I would like to know, Do I need make any changes in vue.config.js?

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

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

发布评论

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

评论(1

情绪失控 2025-01-18 20:56:29

PostCSS 错误

Vue CLI 脚手架项目 已经包含 PostCSS (包括 postcss< /code>、postcss-calcpostcss-loader),因此您无需在项目中安装它。这里唯一需要的依赖是 postcss-custom-properties

要解决 PostCSS 错误,您应该卸载错误添加的 PostCSS 依赖项:

npm uninstall --save-dev postcss postcss-calc postcss-loader

从头开始

要在 Vue CLI 脚手架项目中为 FullCalendar 设置自定义颜色:

  1. 安装 postcss-custom-properties与:

    npm install --save-dev postcss-custom-properties
    
  2. 使用以下 PostCSS 配置创建 postcss.config.js

    // /postcss.config.js
    模块. 导出 = {
      插件:[
        需要(“postcss-自定义属性”)({
          保留:假,
          导入来源:[
            “客户端/fullcalendar-vars.css”,
          ],
        }),
        需要(“postcss-calc”),
      ],
    }
    
  3. 使用以下 CSS 创建 fullcalendar-vars.css

    /* /client/fullcalendar-vars.css */
    :根 {
      --fc-边框颜色:绿色;
      --fc-按钮-文本-颜色:#ff0000;
    }
    

    注意:对此文件的更改不会热重新加载,因此开发服务器必须重新启动才能反映任何更新。

  4. 启动 Vue CLI 开发服务器:

    npm runserve
    

demo< /a>

PostCSS error

Vue CLI scaffolded projects already include PostCSS (including postcss, postcss-calc, and postcss-loader), so you don't need to install it in your project. The only dependency needed here is postcss-custom-properties.

To resolve the PostCSS error, you should uninstall the PostCSS dependencies that you had mistakenly added:

npm uninstall --save-dev postcss postcss-calc postcss-loader

Starting from scratch

To setup custom colors for FullCalendar in a Vue CLI scaffolded project:

  1. Install postcss-custom-properties with:

    npm install --save-dev postcss-custom-properties
    
  2. Create postcss.config.js with the following PostCSS configuration:

    // <projectRoot>/postcss.config.js
    module.exports = {
      plugins: [
        require("postcss-custom-properties")({
          preserve: false,
          importFrom: [
            "client/fullcalendar-vars.css",
          ],
        }),
        require("postcss-calc"),
      ],
    }
    
  3. Create fullcalendar-vars.css with the following CSS:

    /* <projectRoot>/client/fullcalendar-vars.css */
    :root {
      --fc-border-color: green;
      --fc-button-text-color: #ff0000;
    }
    

    Note: Changes to this file are not hot-reloaded, so the dev server must be restarted to reflect any updates.

  4. Start the Vue CLI dev server with:

    npm run serve
    

demo

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