fs.readFile(file, "utf-8", function (err, data) { if (err) { console.log("Something bad happened while minifying css."); console.log(err); process.exit(1); } else { fs.writeFile(file, cssmin(data), function () { baton.pass(); }); } });
minify = exports.minify = function (basePath, fromFile, toFile) { "use strict"; fromFile = path.join(basePath, fromFile); toFile = path.join(basePath, toFile); var dirname = path.dirname(toFile), extName = path.extname(toFile), fileContents, jsp, pro, ast; if (!path.existsSync(dirname)) { throw new Error('"' + dirname +'" does not exists!'); } if (!path.existsSync(fromFile)) { throw new Error('"' + fromFile +'" does not exists!'); } fileContents = fs.readFileSync(fromFile, 'utf8'); // JS if (extName === '.js') { jsp = uglify.parser; pro = uglify.uglify; ast = jsp.parse(fileContents); // parse code and get the initial AST ast = pro.ast_mangle(ast); // get a new AST with mangled names ast = pro.ast_squeeze(ast); // get an AST with compression optimizations fileContents = pro.gen_code(ast); // compressed code here // CSS } else if (extName === '.css') { fileContents = cssmin.cssmin(fileContents); } // Write file writeFile(toFile, fileContents); console.log('Minified'); printSizeAndFile(fileContents.length, toFile) },
postcss([ autoprefixer ]).process(css).then(function (result) { result.warnings().forEach(function (warn) { console.warn(warn.toString() + " " + f); }); var cssFileInDir = PATH.join(destDir, cssFile); grunt.log.writeln(cssFileInDir + " - saving..."); var css = result.css; // hack to remove relative URLs in kendo.theme.mobile.css files // pending removal once styles/{mobile,web,dataviz} folders are gone css = css.replace(/\.\.\/mobile\//g, ''); grunt.file.write(cssFileInDir, css); var cssmin = CSSMIN(css); var cssMinFileInDir = PATH.join(destDir, f.replace(/\.less$/, ".min.css")); grunt.log.writeln(cssMinFileInDir + " - saving..."); grunt.file.write(cssMinFileInDir, cssmin); if (--fileCount === 0) { done(true); } });
Joiner.prototype.minify = function (pack, content) { switch (pack.type) { case "js": // Uglify var ast = uglify.parser.parse(content); ast = uglify.uglify.ast_mangle(ast); ast = uglify.uglify.ast_squeeze(ast); content = uglify.uglify.gen_code(ast); break; case "css": // CSS Min content = cssmin(content); break; } // Feedback sys.puts(" > Joiner: Compressed " + pack.type + " file to " + content.length + " KB."); return content; };
Joiner.prototype.minify = function (content) { // Abstract Syntax Tree generated from JS code (only for uglify-js) var ast, // Final code minified; log('Minifying the raw data.'); switch (this.metadata.type) { // Uglify case 'js': ast = uglify.parser.parse(content); ast = uglify.uglify.ast_mangle(ast); ast = uglify.uglify.ast_squeeze(ast); minified = uglify.uglify.gen_code(ast); break; // CSS Min case 'css': minified = cssmin(content); break; } return minified; };
if (encoding !== this.encoding) { /*jshint ignore:start*/ var text = this.text; // Make sure this._text exists so the rawSrc is decoded before the original encoding is thrown away /*jshint ignore:end*/ delete this._rawSrc; this._encoding = encoding; this.markDirty(); } }, get text() { if (!('_text' in this)) { if (this._parseTree) { this._text = this._parseTree.toString(); if (!this.isPretty) { this._text = cssmin.cssmin(this._text); } } else { this._text = this._getTextFromRawSrc(); } } return this._text; }, get parseTree() { if (!this._parseTree) { // CSSOM gets the @charset declaration mixed up with the first selector: try { this._parseTree = cssom.parse(this.text.replace(/@charset\s*([\'\"])\s*[\w\-]+\s*\1;/, '')); } catch (e) { var err = new errors.ParseError({
function complete() { if (options.css == "inline" || options.css == "compress") { source = cssmin(source); } cb(0, source); }