How to use reaction require syntax?

I see many examples for structured syntax reactions var React = require('react'). When I try to use this, I get "require not defined". How to use and configure my static project to use the required syntax?

Update

I'm actually looking for a webpack / browserify configuration file to get started quickly with React and CommonJS. I just wrote applications for applications without the specified build tools

+4
source share
2 answers

require is not a React api, and it is not a native api browser (yet).

require commonjs node.js, node.js, , .

- node, , , nodejs, .

require, , (, , )

require, , webpack , .

'index.js'

require('./app.js');
alert('index works');

app.js

alert('app works');

next cli

npm install -g browserify

browserify index.js > bundle.js

bundle.js, html

<script src="bundle.js"></script>

,

, ,

npm install react --save

app.js,

var React = require('react');

React.createClass({
    render: function(){/*Blah Blah Blah*/}
})
+8

BTW, webpack, webpack.config.js , :

 plugins: [
            new webpack.ProvidePlugin({
              'React':     'react',
              '$':          'jquery',
              '_':          'lodash',
              'ReactDOM':   'react-dom',
              'cssModule':  'react-css-modules',
              'Promise':    'bluebird'
            })

        ],

, , , , :)

+3

Source: https://habr.com/ru/post/1612507/


All Articles