lintdocs and minify scripts
This commit is contained in:
parent
693c87f5f1
commit
8594ed3ef1
3 changed files with 163 additions and 2 deletions
49
bundler/minify.js
Normal file
49
bundler/minify.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
var http = require("http")
|
||||
var querystring = require("querystring")
|
||||
var fs = require("fs")
|
||||
|
||||
var code = fs.readFileSync("./mithril.js", "utf8")
|
||||
|
||||
var data = {
|
||||
output_format: "json",
|
||||
output_info: ["compiled_code", "warnings", "errors", "statistics"],
|
||||
compilation_level: "SIMPLE_OPTIMIZATIONS",//ADVANDED_OPTIMIZATIONS
|
||||
warning_level: "default",
|
||||
output_file_name: "default.js",
|
||||
js_code: code,
|
||||
}
|
||||
|
||||
var body = querystring.stringify(data)
|
||||
|
||||
var req = http.request({
|
||||
method: "POST",
|
||||
protocol: "http:",
|
||||
hostname: "closure-compiler.appspot.com",
|
||||
path: "/compile",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
|
||||
"Content-Length": body.length
|
||||
}
|
||||
}, function(res) {
|
||||
res.on("data", function(chunk) {
|
||||
response += chunk.toString()
|
||||
})
|
||||
res.on("end", function() {
|
||||
var results = JSON.parse(response)
|
||||
var stats = results.statistics
|
||||
console.log("Original size: " + format(stats.originalGzipSize) + " bytes gzipped (" + format(stats.originalSize) + " bytes uncompressed)")
|
||||
console.log("Compiled size: " + format(stats.compressedGzipSize) + " bytes gzipped (" + format(stats.compressedSize) + " bytes uncompressed)")
|
||||
|
||||
fs.writeFileSync("mithril.min.js", results.compiledCode, "utf8")
|
||||
})
|
||||
})
|
||||
|
||||
var response = ""
|
||||
|
||||
req.write(body)
|
||||
req.end()
|
||||
console.log("compiling...")
|
||||
|
||||
function format(n) {
|
||||
return n.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue