<legend id='Nf70O'><style id='Nf70O'><dir id='Nf70O'><q id='Nf70O'></q></dir></style></legend>
      <i id='Nf70O'><tr id='Nf70O'><dt id='Nf70O'><q id='Nf70O'><span id='Nf70O'><b id='Nf70O'><form id='Nf70O'><ins id='Nf70O'></ins><ul id='Nf70O'></ul><sub id='Nf70O'></sub></form><legend id='Nf70O'></legend><bdo id='Nf70O'><pre id='Nf70O'><center id='Nf70O'></center></pre></bdo></b><th id='Nf70O'></th></span></q></dt></tr></i><div id='Nf70O'><tfoot id='Nf70O'></tfoot><dl id='Nf70O'><fieldset id='Nf70O'></fieldset></dl></div>
        <tfoot id='Nf70O'></tfoot>
      1. <small id='Nf70O'></small><noframes id='Nf70O'>

        • <bdo id='Nf70O'></bdo><ul id='Nf70O'></ul>

        禁用 chrome react DevTools 进行生产

        时间:2023-05-28
        <i id='GLR4L'><tr id='GLR4L'><dt id='GLR4L'><q id='GLR4L'><span id='GLR4L'><b id='GLR4L'><form id='GLR4L'><ins id='GLR4L'></ins><ul id='GLR4L'></ul><sub id='GLR4L'></sub></form><legend id='GLR4L'></legend><bdo id='GLR4L'><pre id='GLR4L'><center id='GLR4L'></center></pre></bdo></b><th id='GLR4L'></th></span></q></dt></tr></i><div id='GLR4L'><tfoot id='GLR4L'></tfoot><dl id='GLR4L'><fieldset id='GLR4L'></fieldset></dl></div>
          <tbody id='GLR4L'></tbody>
        <legend id='GLR4L'><style id='GLR4L'><dir id='GLR4L'><q id='GLR4L'></q></dir></style></legend>

        <small id='GLR4L'></small><noframes id='GLR4L'>

          1. <tfoot id='GLR4L'></tfoot>

                <bdo id='GLR4L'></bdo><ul id='GLR4L'></ul>

                  本文介绍了禁用 chrome react DevTools 进行生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试使用 gulp 浏览我的 react 应用程序以进行生产,并 envify 设置 NODE_ENV.所以我可以删除反应警告,控制台中的错误报告,甚至我的代码来禁用一些功能,比如 react-addons-perf 的要求.

                  I'm trying to browserify my react app for production using gulp and envify to setup NODE_ENV. So I can remove react warning, error reporting in the console, and even my code to disable some features like the require of react-addons-perf.

                  而且效果很好.当我在我的 app.js 中搜索生产"以查看是否存在这些典型条件时:

                  And it's working great. When I search in my app.js for "production" to see if there are theses typical conditions :

                  if("development" !== "production") {
                      ...
                  }
                  

                  什么都没有,所以,正如我所说,它似乎运作良好.

                  There is nothing, so, as I said, it seems to work well.

                  但是,我仍然可以看到带有所有 react 组件的 chrome 的 react DevTools 选项卡,就像我在开发网站上一样.如何在 chrome 的开发工具中禁用此选项卡?

                  But, I still can see that chrome's react DevTools tab with all react components, like if I was on a development website. How can I disable this tab in chrome's dev tools ?

                  这是我的 gulp 任务:

                  Here is my gulp task :

                  var production  = process.env.NODE_ENV === 'production' ? true : false;
                  var environment = process.env.NODE_ENV ? process.env.NODE_ENV : 'dev';
                  
                  ...
                  
                  var bundler = browserify({
                      debug: !production,
                  
                      // These options are just for Watchify
                      cache: {}, packageCache: {}, fullPaths: true
                  })
                  .require(require.resolve('./dev/client/main.js'), { entry: true })
                  .transform(envify({global: true, _: 'purge', NODE_ENV: environment}), {global: true})
                  .transform(babelify)
                  .transform(reactify);
                  
                  var start = Date.now();
                  bundler.bundle()
                      .on('error', function (err) {
                          console.log(err.toString());
                          this.emit("end");
                      })
                      .pipe(source('main.js'))
                      .pipe(gulpif(options.uglify, streamify(uglify())))
                      .pipe(gulpif(!options.debug, streamify(stripDebug())))
                      .pipe(gulp.dest(options.dest))
                      .pipe(notify(function () {
                          console.log('Built in ' + (Date.now() - start) + 'ms');
                      }));
                  };
                  

                  推荐答案

                  根据 Github 上的一个问题,你可以在 react 加载前添加 run 单行 javascript 来防止它.

                  According to an issue on Github, you can add run a single javascript line before react is loaded to prevent it.

                  来自 #191 of react-devtools

                  <script>
                  window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject = function () {}
                  </script>
                  

                  然后,您可以考虑将其与您的环境条件一起包装,就像您可以在服务器端渲染中执行以下操作一样.比方说哈巴狗(以前称为 Jade):

                  Then, you may consider wrapping this with your environment condition, like that you could do sth like below in your server side rendering. Let's say Pug (formerly known as Jade):

                  #{process.env.NODE_ENV == 'production' ? "window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject = function(){}" : ""}
                  

                  但是,将业务逻辑和敏感数据放回您的服务器仍然是一个好习惯.

                  However, it would be still a good practice to put the business logic and the sensitive data back to your server.

                  这篇关于禁用 chrome react DevTools 进行生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:gulp babel,未定义导出 下一篇:gulp:自动为请求添加版本号以防止浏览器缓存

                  相关文章

                  最新文章

                    <bdo id='edCiC'></bdo><ul id='edCiC'></ul>
                  <legend id='edCiC'><style id='edCiC'><dir id='edCiC'><q id='edCiC'></q></dir></style></legend>

                  <tfoot id='edCiC'></tfoot>

                  <small id='edCiC'></small><noframes id='edCiC'>

                1. <i id='edCiC'><tr id='edCiC'><dt id='edCiC'><q id='edCiC'><span id='edCiC'><b id='edCiC'><form id='edCiC'><ins id='edCiC'></ins><ul id='edCiC'></ul><sub id='edCiC'></sub></form><legend id='edCiC'></legend><bdo id='edCiC'><pre id='edCiC'><center id='edCiC'></center></pre></bdo></b><th id='edCiC'></th></span></q></dt></tr></i><div id='edCiC'><tfoot id='edCiC'></tfoot><dl id='edCiC'><fieldset id='edCiC'></fieldset></dl></div>