ionic如何uglify和minify你的js,css,image,png....

Install:
   1.ionic start myapp blank 
    2.cd myapp
    3.npm install cordova-uglify or npm install cordova-uglify --legacy-bundling
Useage:
1.找到hooks/uglify-config.json
2.将第一行代码"alwaysRun": false 改为"alwaysRun": true,
3.运行ionic platform add android,ionic build android 
4.查看plaforms/android/assets/www/目录下的所有文件,是否uglify和minify
ionic如何uglify和minify你的js,css,image,png....
U福利:(自动js纠错功能) 
1.安装:
npm install jshint
npm install async
2.手动新建文件
 在hooks目录下新建文件夹“before_prepare”,该文件夹下新建文件“02_jshint.js”
 将以下内容粘贴到新建文件里:
 #!/usr/bin/env node

 var fs = require('fs');
var path = require('path');
var jshint = require('jshint').JSHINT;
var async = require('async'); var foldersToProcess = [
'js'
]; foldersToProcess.forEach(function(folder) {
processFiles("www/" + folder);
}); function processFiles(dir, callback) {
var errorCount = 0;
fs.readdir(dir, function(err, list) {
if (err) {
console.log('processFiles err: ' + err);
return;
}
async.eachSeries(list, function(file, innercallback) {
file = dir + '/' + file;
fs.stat(file, function(err, stat) {
if(!stat.isDirectory()) {
if(path.extname(file) === ".js") {
lintFile(file, function(hasError) {
if(hasError) {
errorCount++;
}
innercallback();
});
} else {
innercallback();
}
} else {
innercallback();
}
});
}, function(error) {
if(errorCount > 0) {
process.exit(1);
}
});
});
} function lintFile(file, callback) {
console.log("Linting " + file);
fs.readFile(file, function(err, data) {
if(err) {
console.log('Error: ' + err);
return;
}
if(jshint(data.toString())) {
console.log('File ' + file + ' has no errors.');
console.log('-----------------------------------------');
callback(false);
} else {
console.log('Errors in file ' + file);
var out = jshint.data(),
errors = out.errors;
for(var j = 0; j < errors.length; j++) {
console.log(errors[j].line + ':' + errors[j].character + ' -> ' + errors[j].reason + ' -> ' +
errors[j].evidence);
}
console.log('-----------------------------------------');
callback(true);
}
});
}

3.重新运行ionic build android

 将在编译过程看到一下代码
 ionic如何uglify和minify你的js,css,image,png....
表示你的js代码没有错误!
上一篇:Android - Android Studio 解决访问被墙的问题


下一篇:带你十天轻松搞定 Go 微服务系列(二)