keithsun80
V2EX  ›  问与答

React Requirejs 问题

  •  
  •   keithsun80 · Dec 21, 2015 · 2801 views
    This topic created in 3838 days ago, the information mentioned may be changed or developed.

    'use strict';

    requirejs.config({
    baseUrl: 'app/modules',
    paths: {
    app: '../components'
    }
    });

    requirejs(['app/main']);

    main.js

    'use strict';

    define(function (require) {
    var React = require('/app/modules/react.js')
    var ReactDOM = require('/app/modules/react-dom.js')
    var CommentBox = React.createClass({
    render: function() {
    return (
    <div className="commentBox">
    Hello, world! I am a CommentBox.
    </div>
    );
    }
    });

    ReactDOM.render(<CommentBox />, document.getElementById('app'));
    console.log("come here");
    

    });

    我看如果 React 代码带有 xml 标签的内容 必须要如下引用
    <script type="text/babel" src="./app/app.js"></script>

    但是在 requirejs 中如何以这种方式加载呢?

    望各位指点迷津, 顺便分享下, 一个后端程序员 如何介入 React , 并用其和 Python web framework 搭配使用.

    小项目的前端的障碍...要远远大于后端啊........

    2 replies    2015-12-22 10:10:54 +08:00
    yoa1q7y
        1
    yoa1q7y  
       Dec 21, 2015   ❤️ 1
    webpack + reactjs 是标配啊
    gouflv
        2
    gouflv  
       Dec 22, 2015
    跟 requires 说再见吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1661 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 16:20 · PVG 00:20 · LAX 09:20 · JFK 12:20
    ♥ Do have faith in what you're doing.