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

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

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

      <tfoot id='UUfCH'></tfoot>
    1. <legend id='UUfCH'><style id='UUfCH'><dir id='UUfCH'><q id='UUfCH'></q></dir></style></legend>
      1. 使用browserify打包React组件

        时间:2023-05-29

      2. <tfoot id='6qVC2'></tfoot>

        • <bdo id='6qVC2'></bdo><ul id='6qVC2'></ul>
            <tbody id='6qVC2'></tbody>
          <legend id='6qVC2'><style id='6qVC2'><dir id='6qVC2'><q id='6qVC2'></q></dir></style></legend>

          <small id='6qVC2'></small><noframes id='6qVC2'>

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

                • 本文介绍了使用browserify打包React组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试学习 browserify 来管理我的 javascript.我的第一个简单任务是创建一个 react.js 文件,该文件将由 gulp + browserify 生成

                  I am trying to learn browserify to manage my javascript. My first simple task is to create a react.js file which will be generated by gulp + browserify

                  var browserify = require('gulp-browserify');
                  
                  gulp.task('browserify-react', function () {
                    return gulp.src('js/react/react.js')
                    .pipe(browserify())
                    .pipe(rename('react-generated.js'))
                    .pipe(gulp.dest('./dist'));
                  });
                  

                  在 js/react/我创建了一个文件 react.js ,它只有两个 require 命令:

                  In js/react/ I created a file react.js which is just two require commands:

                  var React = require('react');
                  var ReactDOM = require('react-dom');
                  

                  我希望新文件 react-generated.js 包含 react 和 react-dom 模块.

                  I expect that a new file react-generated.js will content a react and react-dom modules.

                  会生成文件,但是当我尝试在我的项目中使用这个 react-generated.js 时出现两个错误

                  File will be generated, but when I try to use this react-generated.js in my project I get two errors

                  ReferenceError: React is not defined
                  ReferenceError: ReactDOM is not defined
                  

                  但如果我使用来自 facebook 的 react javascript,那么一切正常,没有错误

                  But if I use react javascript from facebook, so everything is ok, no errors

                  <script src="https://fb.me/react-0.14.0.min.js"></script>
                  <script src="https://fb.me/react-dom-0.14.0.min.js"></script>
                  

                  问题.当我使用 gulp-browserify 生成 react 组件时,我错过了什么?

                  Questions. What do I miss when I generate react components by using of gulp-browserify?

                  推荐答案

                  您的 react.js 文件/模块未公开您实例化的变量 ReactReactDOM.在节点中,您可以通过修改 module.exports 对象来公开这些方法,如下所示:

                  Your react.js file/module isn't exposing the variables React and ReactDOM you instantiate. In node, you make these methods public by modifying the module.exports object like so:

                  module.exports = {
                    React: React,
                    ReactDOM: ReactDOM
                  }
                  

                  这篇关于使用browserify打包React组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Gulp注入不起作用 下一篇:Node.js 事件流:在哪里设置 MaxListeners?

                  相关文章

                  最新文章

                    <legend id='opIwr'><style id='opIwr'><dir id='opIwr'><q id='opIwr'></q></dir></style></legend><tfoot id='opIwr'></tfoot>

                      <bdo id='opIwr'></bdo><ul id='opIwr'></ul>
                    1. <small id='opIwr'></small><noframes id='opIwr'>

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