Bläddra i källkod

strip log and warn in production build.

Evan You 12 år sedan
förälder
incheckning
3759313d9d
3 ändrade filer med 35 tillägg och 26 borttagningar
  1. 2 3
      src/compiler.js
  2. 25 22
      src/utils.js
  3. 8 1
      tasks/build.js

+ 2 - 3
src/compiler.js

@@ -11,7 +11,6 @@ var Emitter     = require('./emitter'),
     // cache methods
     slice       = [].slice,
     each        = [].forEach,
-    log         = utils.log,
     makeHash    = utils.hash,
     extend      = utils.extend,
     def         = utils.defProtected,
@@ -50,7 +49,7 @@ function Compiler (vm, options) {
 
     // initialize element
     var el = compiler.el = compiler.setupElement(options)
-    log('\nnew VM instance: ' + el.tagName + '\n')
+    utils.log('\nnew VM instance: ' + el.tagName + '\n')
 
     // set compiler properties
     compiler.vm = el.vue_vm = vm
@@ -586,7 +585,7 @@ CompilerProto.bindDirective = function (directive) {
  */
 CompilerProto.createBinding = function (key, isExp, isFn) {
 
-    log('  created binding: ' + key)
+    utils.log('  created binding: ' + key)
 
     var compiler = this,
         bindings = compiler.bindings,

+ 25 - 22
src/utils.js

@@ -163,28 +163,6 @@ var utils = module.exports = {
         }
     },
 
-    /**
-     *  log for debugging
-     */
-    log: function (msg) {
-        if (config.debug && console) {
-            console.log(msg)
-        }
-    },
-    
-    /**
-     *  warnings, traces by default
-     *  can be suppressed by `silent` option.
-     */
-    warn: function (msg) {
-        if (!config.silent && console) {
-            console.warn(msg)
-            if (config.debug && console.trace) {
-                console.trace(msg)
-            }
-        }
-    },
-
     /**
      *  used to defer batch updates
      */
@@ -222,4 +200,29 @@ var utils = module.exports = {
             el.className = cur.trim()
         }
     }
+}
+
+enableDebug()
+function enableDebug () {
+    /**
+     *  log for debugging
+     */
+    utils.log = function (msg) {
+        if (config.debug && console) {
+            console.log(msg)
+        }
+    }
+    
+    /**
+     *  warnings, traces by default
+     *  can be suppressed by `silent` option.
+     */
+    utils.warn = function (msg) {
+        if (!config.silent && console) {
+            console.warn(msg)
+            if (config.debug && console.trace) {
+                console.trace(msg)
+            }
+        }
+    }
 }

+ 8 - 1
tasks/build.js

@@ -52,7 +52,14 @@ function header (file, cb) {
 
 function uglify (file, cb) {
     file.contents = new Buffer(uglifyjs.minify(file.contents.toString(), {
-        fromString: true
+        fromString: true,
+        compress: {
+            pure_funcs: [
+                'utils.log',
+                'utils.warn',
+                'enableDebug'
+            ]
+        }
     }).code)
     cb(null, file)
 }