a library to min or copy your site's everything. split large project to small part. support dojo define. 这是一个能把你的站点文件中能压缩的压缩,不能压缩的复制出, 从而分出一个新的project的类库. 主要用作自动的把庞大的项目分割成可用的小项目. 因为可以copy,所以理论上只要有分拣需求,不是网站也能用(→_→)
- $ npm install uglifysite --save-dev
手中项目结构复杂,工作需要经常将代码按功能模块拆分成小型可用系统.初步尝试使用webpack,但是可能是我太菜,由于项目使用了arcgis api for javascript, 打包屡次失败, 恼羞成怒┴─┴︵╰(‵□′╰).考虑到各种框架的兼容性,再踩坑下去可能要跪,干脆就做了这么一个可以单纯压缩分解庞大项目的工具.
in my case,站点整体体积大约减少45% ★,°:.☆( ̄▽ ̄)/$:.°★。撒花!
- clean target folder before start (you set
clearExportDir
tofalse
to disable this features in config file). - uglify
.js
.css
file. if minify failed,the file will be copy to the target folder. - copy
everything
to target folder. - support custom config, such like your module's
name
copyEntry
scriptEntry
htmlEntry
styleEntry
linkMods
target folder and some other things with api or js file. - with modules's
linkMods
i can find module's module recursively . with this sometimes you don't have to write too many names to solve a lot of files when your module have defined it's reference. - entry's config support
*
to get it's children(child's children not included),**
to get it's children(child's children is included) and Regular expression. - support commander . please tap
-h
to get more details - download from npm
- check and support other type like
scss
less
and so on - make a Better Progressbar
- open loader function api for custom type file
- simple document
- example
- do something for
.html
files - combine two
.js
or.css
files if allowed - try to kill images that no use
- faster and faster
//basic use if your config file live in some other folder
$ uglifysite -c ./xxx/xxxx.js -m mod1,mod2...
// if you have a uglify.config.js file in your root just use this
$ uglifysite -m mod1,mod2...
//-c is set config file path , default is uglify.config.js in the root
$ -c xxxx/xxx/xxxxx.js
//-m is set which module should be pack, can be a list split by \,\ .
// accept data is the name of some modules that defined in your config file
$ -m XXX1,XXX2,XXX3
// -m all means build all module defined in config file
$ -m all
// other params
$ --copy //mens do not build or uglify just copy
$ --clear //mens clear target folder before build
let uglifySite = require('uglifySite');
uglifySite
.setConfig('./uglify.config.js') //.setConfig(configObj)
.then(res=>{
return uglifySite.start('modName or modNames array')
//uglifySite.start('all');//do with all modules that defined in config
//uglifySite.start('XXX');
//uglifySite.start(['XXX1','XXX2']);
})
.then(()=>{
//done
})
- a basic config file
module.exports = {
dir: './dist/', //输出根目录 export to where
clearExportDir: true, //干活前是否清空输出目录, if clear target dir before work
modules: [
//模块1 module1
//模块2 module2
//模块3 module3
...
]
}
- every defined module is a obj that has some parameters
{
name:'common', //module's unique name
linkMods: ['XXXX1','XXXX2'], // reference modules's name.
styleEntry{ //style files's location
test:"XXXX/XXXX.CSS"
},
scriptEntry:{ //script files's location
test:"XXXX/XXXX.js"
},
htmlEntry:{//html files's location
test:"XXXX/XXXX.html"
},
copyEntry:{ //other files's location
test:"XXXX/XXXX" //no extName === folder
}
}
- all entry support several location types => obj tree, string||string[], Regular expression...
//string
scriptEntry:{
test:'example/js/index.js'
}
//string[]
scriptEntry:{
test:['example/js/index.js','example/js/index2.js']
}
//obj tree
scriptEntry:{
example:{
js:{
test:['index.js','index2.js']
}
}
}
//Regular expression in '{}'
scriptEntry:{
test:'script/menu/{.+\.js}', //mean: script/menu/all js file
}
// all test also support * and ** . (mostly used by copyEntry)
copyEntry:{
test:'fonts/*', //mean: all file in fonts (child's children excluded)
}
copyEntry:{
test:'fonts/**', //mean: all file in fonts (child's children included)
}
// obj tree support * and ** and regular expression too
copyEntry:{
fonts:{
test:'**'
}
}