{"id":25629,"library":"glass-easel-stylesheet-compiler","title":"glass-easel-stylesheet-compiler","description":"A Rust-based stylesheet compiler for the glass-easel project, version 0.19.0. It converts rpx units to vw, applies class-prefix-based style isolation, and minifies CSS. Maintained by WeChat Mini Program team, it prioritizes performance via WebAssembly. Alternatives like PostCSS plugins exist but lack integrated class-prefixing.","status":"active","version":"0.19.0","language":"javascript","source_language":"en","source_url":"https://github.com/wechat-miniprogram/glass-easel","tags":["javascript","glass-easel","typescript"],"install":[{"cmd":"npm install glass-easel-stylesheet-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add glass-easel-stylesheet-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add glass-easel-stylesheet-compiler","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export is an object with named StyleSheetTransformer; named import is preferred for ESM.","wrong":"const StyleSheetTransformer = require('glass-easel-stylesheet-compiler')","symbol":"StyleSheetTransformer","correct":"import { StyleSheetTransformer } from 'glass-easel-stylesheet-compiler'"},{"note":"CommonJS users must destructure the named export; there is no default export.","wrong":"const StyleSheetTransformer = require('glass-easel-stylesheet-compiler').default","symbol":"StyleSheetTransformer","correct":"const { StyleSheetTransformer } = require('glass-easel-stylesheet-compiler')"},{"note":"For TypeScript projects only using the type (e.g., as a parameter), use import type to avoid runtime import.","wrong":"import { StyleSheetTransformer } from 'glass-easel-stylesheet-compiler' when only type needed","symbol":"StyleSheetTransformer type","correct":"import type { StyleSheetTransformer } from 'glass-easel-stylesheet-compiler'"}],"quickstart":{"code":"import { readFileSync } from 'fs';\nimport { StyleSheetTransformer } from 'glass-easel-stylesheet-compiler';\n\nconst cssContent = readFileSync('styles.css', 'utf8');\nconst classPrefix = 'my-app';\nconst rpxRatio = 750;\nconst transformer = new StyleSheetTransformer('/path/to/styles.css', cssContent, classPrefix, rpxRatio);\nconst output = transformer.getContent();\nconst sourceMap = transformer.toSourceMap();\ntransformer.free();\nconsole.log(output);\nconsole.log(sourceMap);","lang":"typescript","description":"Reads a CSS file, creates a StyleSheetTransformer with a class prefix and rpx ratio, then gets the transformed CSS and source map."},"warnings":[{"fix":"Call transformer.free() when done, or use a try/finally block.","message":"The StyleSheetTransformer must be freed after use to release memory, especially in long-running processes.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always provide an absolute or relative file path (e.g., '/path/to/file.css') that matches the source map expectations.","message":"The first argument to the constructor is a file path (string). If you pass a URL or empty string, behavior may be undefined.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure rpxRatio matches your design width (typically 750).","message":"rpxRatio should be based on a 750px design width; using an incorrect ratio leads to incorrect vw conversions.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use Buffer.from(sourceMap).toString() or new TextDecoder().decode(sourceMap) to get a JSON string.","message":"The source map returned by toSourceMap() is a raw Uint8Array, not a JSON string. Users must convert it manually if needed.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use correct import: `import { StyleSheetTransformer } from 'glass-easel-stylesheet-compiler'`","cause":"Using an incorrect import pattern that returns a module object instead of the class.","error":"TypeError: Class extends value #<Object> is not a constructor or null"},{"fix":"Run `npm install glass-easel-stylesheet-compiler`","cause":"Package not installed or missing from node_modules.","error":"Error: Cannot find module 'glass-easel-stylesheet-compiler'"},{"fix":"Ensure you correctly imported `StyleSheetTransformer` and called `new StyleSheetTransformer(...)`.","cause":"The transformer object is not an instance of StyleSheetTransformer (e.g., wrong import).","error":"TypeError: transformer.free is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}