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

Unified Diff: tools/grit/grit/format/minifier.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 | « tools/grit/grit/format/html_inline.py ('k') | tools/grit/grit/gather/chrome_html.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/format/minifier.py
diff --git a/tools/grit/grit/format/minifier.py b/tools/grit/grit/format/minifier.py
new file mode 100644
index 0000000000000000000000000000000000000000..93d0df72f241cdba0c5aed4e446f3c1ec3288a67
--- /dev/null
+++ b/tools/grit/grit/format/minifier.py
@@ -0,0 +1,30 @@
+# 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.
+"""Framework for stripping whitespace and comments from resource files"""
+
+import subprocess
+
+__js_minifier = None
+
+
+def SetJsMinifier(minifier):
+ global __js_minifier
+ __js_minifier = minifier.split()
+
+
+def Minify(source, file_type):
+ if not file_type == '.js' or not __js_minifier:
+ return source
+ p = subprocess.Popen(
+ __js_minifier,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ (stdout, stderr) = p.communicate(source)
+ if stderr:
+ print stderr
+ if p.returncode != 0:
+ print 'Minification failed, using original source'
+ return source
+ return stdout
« no previous file with comments | « tools/grit/grit/format/html_inline.py ('k') | tools/grit/grit/gather/chrome_html.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698