Browse Source

ignore user timings for production build

Alexander Rose 6 years ago
parent
commit
e9dbeb7760
2 changed files with 10 additions and 6 deletions
  1. 10 4
      src/mol-task/util/user-timing.ts
  2. 0 2
      webpack.config.js

+ 10 - 4
src/mol-task/util/user-timing.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -7,17 +7,23 @@
 import { Task } from '../task'
 
 const hasPerformance = typeof performance !== 'undefined'
+/**
+ * on node `process.env.NODE_ENV` is available, in webpack build it is automatically set
+ * by the DefinePlugin to the webpack `mode` value
+ */
+const productionMode = process.env.NODE_ENV === 'production'
+const timingEnabled = hasPerformance && !productionMode
 
 export namespace UserTiming {
     function startMarkName(task: Task<any>) { return `startTask${task.id}` }
     function endMarkName(task: Task<any>) { return `endTask${task.id}` }
     export function markStart(task: Task<any>) {
-        if (hasPerformance) performance.mark(startMarkName(task))
+        if (timingEnabled) performance.mark(startMarkName(task))
     }
     export function markEnd(task: Task<any>) {
-        if (hasPerformance) performance.mark(endMarkName(task))
+        if (timingEnabled) performance.mark(endMarkName(task))
     }
     export function measure(task: Task<any>) {
-        if (hasPerformance) performance.measure(task.name, startMarkName(task), endMarkName(task))
+        if (timingEnabled) performance.measure(`✳️ ${task.name}`, startMarkName(task), endMarkName(task))
     }
 }

+ 0 - 2
webpack.config.js

@@ -49,8 +49,6 @@ const sharedConfig = {
         }),
         new webpack.DefinePlugin({
             __PLUGIN_VERSION_TIMESTAMP__: webpack.DefinePlugin.runtimeValue(() => `${new Date().valueOf()}`, true),
-            // include this for production version of React
-            // 'process.env.NODE_ENV': JSON.stringify('production')
         }),
         new MiniCssExtractPlugin({ filename: 'app.css' })
     ],