OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 """Framework for stripping whitespace and comments from resource files""" |
| 5 |
| 6 import subprocess |
| 7 |
| 8 __js_minifier = None |
| 9 |
| 10 |
| 11 def SetJsMinifier(minifier): |
| 12 global __js_minifier |
| 13 __js_minifier = minifier.split() |
| 14 |
| 15 |
| 16 def Minify(source, file_type): |
| 17 if not file_type == '.js' or not __js_minifier: |
| 18 return source |
| 19 p = subprocess.Popen( |
| 20 __js_minifier, |
| 21 stdin=subprocess.PIPE, |
| 22 stdout=subprocess.PIPE, |
| 23 stderr=subprocess.PIPE) |
| 24 (stdout, stderr) = p.communicate(source) |
| 25 if stderr: |
| 26 print stderr |
| 27 if p.returncode != 0: |
| 28 print 'Minification failed, using original source' |
| 29 return source |
| 30 return stdout |
OLD | NEW |