PostCSS

PostCSS 允许开发者编写现代 CSS,同时保持向后兼容性并提高性能。它解析 CSS 代码并通过一系列插件对其进行修改、优化和扩展,然后输出最终结果。

使用方法

您可以通过使用以下 Qwik 脚本将 PostCSS 添加到您的项目中:

npm run qwik add postcss

这将在项目的根目录下创建一个新的 postcss.config.js 文件,其中包含以下依赖项和配置。

postcss.config.js
module.exports = {
  plugins: {
    autoprefixer: {},
    "postcss-preset-env": {
      stage: 3,
      features: {
        "nesting-rules": true,
      },
    },
  },
}

如果您希望添加一个新的插件,比如 CssNano,请运行以下命令并更新 postcss.config.js

npm install cssnano --save-dev
postcss.config.js
module.exports = {
  plugins: {
    /* 先前的插件配置 */
    "cssnano": {
      preset: "default"
    }
  },
}

如需进一步了解,请查阅 PostCSS 文档

Contributors

Thanks to all the contributors who have helped make this documentation better!

  • manucorporat
  • manuelsanchezweb
  • manuelsanchez2
  • the-r3aper7
  • mhevery