Evan You 10 лет назад
Родитель
Сommit
bc4b7bb536
2 измененных файлов с 18 добавлено и 21 удалено
  1. 15 20
      src/util/debug.js
  2. 3 1
      src/util/options.js

+ 15 - 20
src/util/debug.js

@@ -1,27 +1,22 @@
 import config from '../config'
 
-/**
- * Enable debug utilities.
- */
+let warn
 
-const hasConsole = typeof console !== 'undefined'
-
-/**
- * We've got a problem here.
- *
- * @param {String} msg
- */
-
-export function warn (msg, e) {
-  if (hasConsole && (!config.silent || config.debug)) {
-    console.warn('[Vue warn]: ' + msg)
-    /* istanbul ignore if */
-    if (config.debug) {
-      if (e) {
-        throw e
-      } else {
-        console.warn((new Error('Warning Stack Trace')).stack)
+if (process.env.NODE_ENV !== 'production') {
+  const hasConsole = typeof console !== 'undefined'
+  warn = function (msg, e) {
+    if (hasConsole && (!config.silent || config.debug)) {
+      console.warn('[Vue warn]: ' + msg)
+      /* istanbul ignore if */
+      if (config.debug) {
+        if (e) {
+          throw e
+        } else {
+          console.warn((new Error('Warning Stack Trace')).stack)
+        }
       }
     }
   }
 }
+
+export { warn }

+ 3 - 1
src/util/options.js

@@ -374,6 +374,8 @@ export function resolveAsset (options, type, id) {
 
 export function assertAsset (val, type, id) {
   if (!val) {
-    warn('Failed to resolve ' + type + ': ' + id)
+    process.env.NODE_ENV !== 'production' && warn(
+      'Failed to resolve ' + type + ': ' + id
+    )
   }
 }