我有两个 JSX 文件(index.js 和 app.jsx)和一个 HTML 文件,我想在 index.js 中导入 app.jsx,这是 index.html 的脚本文件。我想在没有 npm 的情况下直接运行 HTML (index.html)(仅使用 LiveServer)。我该怎么做?
代码:index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Add React in One Minute</title>
</head>
<body>
<h2>Add React in One Minute</h2>
<p>This page demonstrates using React with no build tooling.</p>
<p>React is loaded as a script tag.</p>
<!-- We will put our React component inside this div. -->
<div id="root"></div>
<!-- Load React. -->
<!-- Note: when deploying, replace "development.js" with "production.min.js". -->
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<!-- Load our React component. -->
<!-- <script src="index.js" type="text/babel"></script> -->
</body>
</html>
index.js
import App from './app'; // we are facing issue here!
ReactDOM.render(
<App />,
document.getElementById('root')
);
应用程序.jsx
var App = React.createClass({
render: function() {
return (
<div className="app">
Hello, world!
</div>
);
}
});
export default App