Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Unified Diff: third_party/closure_compiler/js_minify.py

Issue 2179033002: Strip comments and whitespace from javascript resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to screen.js (no longer needed for this CL) Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/closure_compiler/compile2.py ('k') | third_party/closure_compiler/runner/runner.jar » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/closure_compiler/js_minify.py
diff --git a/third_party/closure_compiler/js_minify.py b/third_party/closure_compiler/js_minify.py
new file mode 100755
index 0000000000000000000000000000000000000000..98ae2d24f7e3c97e375d23cea6aed034f9191f8c
--- /dev/null
+++ b/third_party/closure_compiler/js_minify.py
@@ -0,0 +1,50 @@
+#!/usr/bin/python
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+''' Javascript minifier using the closure compiler
+
+This minifier strips spaces and comments out of Javascript using the closure
+compiler. It takes the original Javascript on standard input, and outputs
+the minified output on standard output.
+
+Any errors or other messages from the compiler are output on standard error.
+'''
+
+import argparse
+import sys
+import tempfile
+
+from compile2 import Checker
+
+
+def Minify(source):
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-c", "--closure_args", nargs=argparse.ZERO_OR_MORE,
+ help="Arguments passed directly to the Closure compiler")
+ args = parser.parse_args()
+ with tempfile.NamedTemporaryFile(suffix='.js') as t1, \
+ tempfile.NamedTemporaryFile(suffix='.js') as t2:
+ t1.write(source)
+ t1.seek(0)
+ checker = Checker()
+ (compile_error, compile_stderr) = checker.check(
+ [t1.name],
+ out_file=t2.name,
+ closure_args=args.closure_args)
+ if compile_error:
+ print compile_stderr
+ t2.seek(0)
+ result = t2.read()
+ return result
+
+
+if __name__ == '__main__':
+ orig_stdout = sys.stdout
+ result = ''
+ try:
+ sys.stdout = sys.stderr
+ result = Minify(sys.stdin.read())
+ finally:
+ sys.stdout = orig_stdout
+ print result
« no previous file with comments | « third_party/closure_compiler/compile2.py ('k') | third_party/closure_compiler/runner/runner.jar » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698