admin管理员组文章数量:1415137
I am trying to measure react performance with Perf addon, but when I'm trying to run Perf.start() in my console i get an error: Uncaught ReferenceError: Perf is not defined(…)
Worth mentioning, that I've installed the plugin through npm and have a require('react-addons-perf')
sitting in my main.js file.
I have a guess that this problem related to the fact that i'm running a webpack-dev-server and the global variable is not properly exposed, but unfortunately hav no idea, how to properly approach it. Can anyone help me with that?
Here's my webpack.config file contents on codepen for the reference.
I am trying to measure react performance with Perf addon, but when I'm trying to run Perf.start() in my console i get an error: Uncaught ReferenceError: Perf is not defined(…)
Worth mentioning, that I've installed the plugin through npm and have a require('react-addons-perf')
sitting in my main.js file.
I have a guess that this problem related to the fact that i'm running a webpack-dev-server and the global variable is not properly exposed, but unfortunately hav no idea, how to properly approach it. Can anyone help me with that?
Here's my webpack.config file contents on codepen for the reference.
Share Improve this question asked Jan 22, 2016 at 15:06 Gleb KostyuninGleb Kostyunin 3,8832 gold badges21 silver badges36 bronze badges2 Answers
Reset to default 4I don't know if there might be changes within your webpack.config that could change the scoping or expose a var to be accessible via the global scope, but one quick way would be to simply use
global.Perf = require('react-addons-perf');
This should grant you access via console.
But one must say that it is maybe not intended to expose vars globally global variables in requireJS
And maybe try to find a way to trigger the Perf.start() and Perf.stop() from within your code, not the console!
Found a solution, that worked for me:
- Install the npm expose-loader module
Add the following line to your webpack config loaders:
{ test: require.resolve("react-addons-perf"), loader: "expose?Perf" }
This expose-loader module is a great way to expose module exports to global scope.
本文标签: javascriptPerf is not definedrunning react app with webpackdevserverStack Overflow
版权声明:本文标题:javascript - Perf is not defined - running react app with webpack-dev-server - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745204793a2647586.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论