ReactDOM
依赖于React
在加载之前以顺序方式加载。
我必须使用requirejs
加载脚本,因为我无法更改js
的同步加载。
我已尝试创建测试应用,但我不断收到以下错误:Error: Script error for "react", needed by: helper/react-dom.min
打印hello
后
我尝试过的......
的index.html
<!DOCTYPE html>
<html>
<head>
<title>My Sample Project</title>
<!-- data-main attribute tells require.js to load
scripts/main.js after require.js loads. -->
<script data-main="scripts/main" src="scripts/require.js"></script>
</head>
<body>
<h1>My Sample Project</h1>
</body>
</html>
main.js
require(['helper/react-loader'], function(){
// do something with the loaded modules
console.log('hello);
});
反应-loader.js
require(['helper/react.min','helper/react-dom.min'], function(){
// do something with the loaded modules
console.log('react loaded');
});
答案 0 :(得分:0)
ReactDOM使用define(['react'], f)
来定义模块(see),因此您必须将React模块的名称定义为等于react
,这意味着您配置如下所示的requirejs:
require.config({
paths: {
'react': 'helper/react.min',
}
});