Skip to content
Snippets Groups Projects
Commit e9dbeb77 authored by Alexander Rose's avatar Alexander Rose
Browse files

ignore user timings for production build

parent 2eb1bfe4
No related branches found
No related tags found
No related merge requests found
/** /**
* 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> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
...@@ -7,17 +7,23 @@ ...@@ -7,17 +7,23 @@
import { Task } from '../task' import { Task } from '../task'
const hasPerformance = typeof performance !== 'undefined' 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 { export namespace UserTiming {
function startMarkName(task: Task<any>) { return `startTask${task.id}` } function startMarkName(task: Task<any>) { return `startTask${task.id}` }
function endMarkName(task: Task<any>) { return `endTask${task.id}` } function endMarkName(task: Task<any>) { return `endTask${task.id}` }
export function markStart(task: Task<any>) { export function markStart(task: Task<any>) {
if (hasPerformance) performance.mark(startMarkName(task)) if (timingEnabled) performance.mark(startMarkName(task))
} }
export function markEnd(task: Task<any>) { export function markEnd(task: Task<any>) {
if (hasPerformance) performance.mark(endMarkName(task)) if (timingEnabled) performance.mark(endMarkName(task))
} }
export function measure(task: Task<any>) { 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))
} }
} }
\ No newline at end of file
...@@ -49,8 +49,6 @@ const sharedConfig = { ...@@ -49,8 +49,6 @@ const sharedConfig = {
}), }),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
__PLUGIN_VERSION_TIMESTAMP__: webpack.DefinePlugin.runtimeValue(() => `${new Date().valueOf()}`, true), __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' }) new MiniCssExtractPlugin({ filename: 'app.css' })
], ],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment