@train860/theme-compress
v0.0.7
Published
CLI and library to compress theme assets and update theme.json hashes
Readme
theme-compress
统一的主题静态资源压缩工具,可作为 CLI 或库使用。主要能力:
- 压缩
assets/css与assets/js下的文件至dist/css、dist/js。 - 为文件名追加哈希值并更新
theme.json中的assets映射。 - 提供 CLI 工具
theme-compress方便集成在脚本和 CI/CD 中。
安装
npm install theme-compress --save-dev
# 或者
pnpm add -D theme-compressCLI 使用
npx theme-compress [选项]常用选项:
--root <path>指定主题根目录(默认当前目录)。--assets <path>静态资源目录,相对 root,默认assets。--dist <path>输出目录,相对 root,默认dist。--theme-json <path>theme.json相对路径,默认theme.json。--hash-length <number>文件名哈希长度,默认10。--no-clean禁止清空dist/css与dist/js目录。--silent仅输出错误。
示例:
npx theme-compress --root ../my-theme --hash-length 12编程式使用
const { compressTheme } = require('theme-compress');
(async () => {
await compressTheme({
rootDir: '/path/to/theme',
assetsDir: 'assets',
distDir: 'dist',
themeJson: 'theme.json',
hashLength: 8
});
})();发布准备
- 在项目根目录执行
npm login(首次发布)。 - 切换到
packages/theme-compress/目录。 - 运行
npm publish --access public。
发布前请根据需要更新 version、description 以及 author 字段。
