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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 ''' Javascript minifier using the closure compiler
6
7 This minifier strips spaces and comments out of Javascript using the closure
8 compiler. It takes the original Javascript on standard input, and outputs
9 the minified output on standard output.
10
11 Any errors or other messages from the compiler are output on standard error.
12 '''
13
14 import argparse
15 import sys
16 import tempfile
17
18 from compile2 import Checker
19
20
21 def Minify(source):
22 parser = argparse.ArgumentParser()
23 parser.add_argument("-c", "--closure_args", nargs=argparse.ZERO_OR_MORE,
24 help="Arguments passed directly to the Closure compiler")
25 args = parser.parse_args()
26 with tempfile.NamedTemporaryFile(suffix='.js') as t1, \
27 tempfile.NamedTemporaryFile(suffix='.js') as t2:
28 t1.write(source)
29 t1.seek(0)
30 checker = Checker()
31 (compile_error, compile_stderr) = checker.check(
32 [t1.name],
33 out_file=t2.name,
34 closure_args=args.closure_args)
35 if compile_error:
36 print compile_stderr
37 t2.seek(0)
38 result = t2.read()
39 return result
40
41
42 if __name__ == '__main__':
43 orig_stdout = sys.stdout
44 result = ''
45 try:
46 sys.stdout = sys.stderr
47 result = Minify(sys.stdin.read())
48 finally:
49 sys.stdout = orig_stdout
50 print result
OLDNEW
« 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