0.3.0 • Published 7 years ago
web-nocache v0.3.0
Web-NoCache
重命名所有静态资源,并替换相应的引用路径,用于解决web上线后浏览器缓存静态资源的问题。
Install
npm install web-nocache
Usage
NoCache = require('web-nocache').NoCache
noCache = new NoCache(
sourceContext: './web' # 如果静态文件引用存在绝对路径,则必须指定webroot是什么
outputContext: './build' # 同上,编译后的webroot是什么
)
noCache.processMedia('./web/edit.png', './build/[name].[hash:6].[ext]') # 处理图片
.then ->
noCache.processCss('./web/main.css', './build/[name].[hash:6].css') # 处理css
.then ->
noCache.processJs('./web/main.js', './build/[name].[hash:6].[ext]') # 处理js
.then ->
noCache.processTpl('./web/index.html', './build/[path][name].[ext]') # 最后处理模板
根据文件的依赖关系,处理顺序为:image
-> css
-> js
-> tpl
如果传入数组则进行批量处理
编译后文件路径命名参考: loader-utils
给路径添加cdn
NoCache = require('web-nocache').NoCache
noCache = new NoCache(
sourceContext: './web' # 如果静态文件引用存在绝对路径,则必须指定webroot是什么
outputContext: './build' # 同上,编译后的webroot是什么
cdn: ['//s1.static.com', '//s2.static.com'] # 指定cdn列表, 静态资源将按一定的规律平均分配到各个cdn节点上
)
noCache.processMedia('./web/edit.png', './build/[name].[hash:6].[ext]') # 处理图片
.then ->
noCache.processCss('./web/main.css', './build/[name].[hash:6].css') # 处理css
.then ->
noCache.processJs('./web/main.js', './build/[name].[hash:6].[ext]') # 处理js
.then ->
noCache.processTpl('./web/index.html', './build/[path][name].[ext]') # 最后处理模板
0.3.0
7 years ago
0.2.0
8 years ago
0.1.8
8 years ago
0.1.7
9 years ago
0.1.6
9 years ago
0.1.5
9 years ago
0.1.4
9 years ago
0.1.3
9 years ago
0.1.2
9 years ago
0.1.1
9 years ago
0.1.0
9 years ago
0.0.9
9 years ago
0.0.8
9 years ago
0.0.7
9 years ago
0.0.6
9 years ago
0.0.5
9 years ago
0.0.4
9 years ago
0.0.3
9 years ago
0.0.2
9 years ago
0.0.1
9 years ago