ths-cli-zip
v2.0.0
Published
一个简单的替换前端项目中的相对地址为绝对地址
Downloads
4
Readme
ths-cli v1版
一个简单的cdn地址替换命令行工具(适用ths)
工具会对页面中的css,js,以及图片地址进行cdn地址转换,需要在link,script标签添加cdn即可(例如:<link href="./styles/index.css" cdn>
)
js地址可以进行合并也可以针对某个js单独生成cdn地址,如需单独生成才需要在script标签中添加single(例如:<script src="./scripts/index.js" single></script>
),出现single就不必在加cdn,默认会对添加 cdn属性值相等的的script标签 按顺序进行合并。如果添加cdn的标签只有一个则不会使用合并语法。
工具会自动修改css和html文件中的图片引用地址,但不会处理js中的地址
会对js,css文件进行压缩,会保留原始文件,上传静态资源服务器时只需上传压缩文件即可。
安装
npm install ths-cli -g
使用
使用 ths-cli cdn 执行默认的cdn替换
使用 ths-cli cdn -t 20180202指定cdn时间戳
使用 ths-cli init 初始化配置文件
使用 ths-cli create 创建开发目录
使用 ths-cli test 测试替换的cdn地址
配置文件有三个配置项
cdn --> cdn地址
build --> 对应打包后的目录,不能与当前目录中的文件夹同名
ignore --> 打包时需要忽略的目录
版本更新
v2版本更名为ths-cli-zip
- 更新压缩能力
安装
npm install ths-cli-zip -g
使用同V1版本相同,只是cli工具名变更为
ths-cli-zip
- exp:
使用
ths-cli-zip cdn
执行默认的cdn替换
新增配置项prefix, projectName
- prefix => 新增在projectName前面作为上一级的目录例如: 形如${prefix}/${projectName}
- projectName => 默认读取当前项目名
以上都为非必填项
cdn.config.js中配置如下
{
"prefix": '2022',
"projectName": "项目名" // 一般当前项目名与静态资源项目名同步的情况下不需要填写
}
v2.0.0 新增图片,视频hash模式支持[contenthash]
- 因为为初期处理,有问题请及时反馈,发布前需要预发布仔细核对资源是否存在问题。
- 图片视频等资源默认放到assets目录下。(只会给assets目录下的内容对应编译contenthash)