npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

css-transform-to-3d-matrix-plugin

v1.0.0

Published

A webpack plugin that converts CSS transform properties to matrix3d format for better performance

Downloads

1

Readme

CSS Transform to 3D Matrix Plugin

npm version License: MIT

一个Webpack插件,可以将CSS的transform属性自动转换为matrix3d格式,以提升渲染性能并实现更好的GPU加速。

功能特性

  • 🚀 性能优化: 将CSS transform属性转换为matrix3d格式,启用GPU加速
  • 🔧 多种转换支持: 支持translate、rotate、scale、skew等所有常见的transform函数
  • 📦 Webpack兼容: 同时支持Webpack 4和Webpack 5
  • 🎯 文件类型支持: 支持.css、.scss、.less等多种样式文件
  • 🐛 调试模式: 内置调试日志,方便开发时查看转换过程
  • 💡 保留原始: 可选择保留原始transform代码作为注释

为什么使用Matrix3D?

使用matrix3d相比普通的transform属性有以下优势:

  1. GPU加速: matrix3d会触发GPU硬件加速,提升动画性能
  2. 避免重排重绘: 减少浏览器的layout和paint操作
  3. 更好的动画流畅度: 特别是在复杂动画和移动设备上

安装

npm install css-transform-to-3d-matrix-plugin --save-dev

使用方法

基本用法

在你的webpack.config.js中添加插件:

const CSSTransformTo3DMatrixPlugin = require('css-transform-to-3d-matrix-plugin');

module.exports = {
  // ... 其他配置
  plugins: [
    new CSSTransformTo3DMatrixPlugin()
  ]
};

高级配置

const CSSTransformTo3DMatrixPlugin = require('css-transform-to-3d-matrix-plugin');

module.exports = {
  // ... 其他配置
  plugins: [
    new CSSTransformTo3DMatrixPlugin({
      // 是否启用调试模式,显示转换日志
      debug: true,
      
      // 要处理的文件扩展名
      extensions: ['.css', '.scss', '.less'],
      
      // 是否保留原始transform代码作为注释
      keepOriginal: false
    })
  ]
};

配置选项

| 选项 | 类型 | 默认值 | 描述 | |------|------|--------|------| | debug | boolean | false | 启用调试日志 | | extensions | string[] | ['.css', '.scss', '.less'] | 要处理的文件扩展名 | | keepOriginal | boolean | false | 保留原始代码作为注释 |

转换示例

输入 CSS

.element1 { transform: translate(10px, 20px); }
.element2 { transform: rotate(45deg); }
.element3 { transform: scale(1.5); }
.element4 { transform: translate(10px, 20px) rotate(45deg) scale(1.5); }
.element5 { transform: matrix(1, 0, 0, 1, 10, 20); }

输出 CSS

.element1 { transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 10, 20, 0, 1); }
.element2 { transform: matrix3d(0.707107, 0.707107, 0, 0, -0.707107, 0.707107, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
.element3 { transform: matrix3d(1.5, 0, 0, 0, 0, 1.5, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
.element4 { transform: matrix3d(1.06066, 1.06066, 0, 0, -1.06066, 1.06066, 0, 0, 0, 0, 1, 0, -10.606602, 31.819805, 0, 1); }
.element5 { transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 10, 20, 0, 1); }

支持的Transform函数

  • translate(x, y) / translateX(x) / translateY(y) / translateZ(z) / translate3d(x, y, z)
  • rotate(angle) / rotateX(angle) / rotateY(angle) / rotateZ(angle) / rotate3d(x, y, z, angle)
  • scale(x, y) / scaleX(x) / scaleY(y) / scaleZ(z) / scale3d(x, y, z)
  • skew(x, y) / skewX(x) / skewY(y)
  • matrix(a, b, c, d, e, f) / matrix3d(...)

完整的项目集成示例

// webpack.config.js
const path = require('path');
const CSSTransformTo3DMatrixPlugin = require('css-transform-to-3d-matrix-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader'
        ]
      },
      {
        test: /\.scss$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          'sass-loader'
        ]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: 'styles.css'
    }),
    new CSSTransformTo3DMatrixPlugin({
      debug: process.env.NODE_ENV === 'development',
      extensions: ['.css', '.scss'],
      keepOriginal: false
    })
  ]
};

测试

运行测试以查看插件的转换效果:

npm test

这将运行测试脚本,展示各种transform属性的转换结果。

开发和构建脚本

# 运行测试
npm test

# 发布到私有仓库
npm run publish:private

# 发布新版本
npm run publish:patch    # 补丁版本
npm run publish:minor    # 次要版本  
npm run publish:major    # 主要版本

# 检查打包内容
npm run pack:check

浏览器兼容性

  • Chrome: 12+
  • Firefox: 10+
  • Safari: 4+
  • Edge: 12+
  • IE: 10+

注意事项

  1. 构建时转换: 这个插件在构建时进行转换,不会影响运行时性能
  2. 精度处理: 转换后的数值会保留6位小数精度
  3. 错误处理: 如果某个transform无法转换,会保持原样不会中断构建
  4. 调试模式: 建议在开发环境启用debug模式,生产环境关闭

许可证

MIT © ke can

贡献

欢迎提交Issue和Pull Request!

更新日志

v1.0.0

  • 初始版本发布
  • 支持所有常见的transform函数
  • 兼容Webpack 4和5
  • 支持多种样式文件格式