Using reactjs with requirejs

后端 未结 2 691
轮回少年
轮回少年 2020-12-12 10:20

Recently, I started using reactjs along with a backbonejs router to build an application.

I usually use use requirejs for depe

2条回答
  •  温柔的废话
    2020-12-12 10:55

    React tools (JSX included) have been deprecated in favor of Babel (https://facebook.github.io/react/blog/2015/06/12/deprecating-jstransform-and-react-tools.html). I cannot find a way to do this without a "transpiling" step, so this is my solution with grunt.

    You can instal grunt-babel (npm install grunt-babel) and configure a task like the following:

    babel: {
        options: {
            sourceMap: false,
            modules: "common"
        },
        dist: {
            files: [{
                expand: true,
                src: ['js/components/*.jsx'],
                dest: 'dist',
                ext:'.js'
           }]
        }
    }
    

    Just add it to your list of grunt tasks:

    grunt.registerTask('default', ['clean', 'copy', 'babel', 'http-server']);
    

    Babel will transpile your JSX to JS files that can be specified as RequireJS dependencies with no additional configuration.

提交回复
热议问题