0
我在網上看到的代碼這樣一個非常簡單的反應程序:你是否必須在你的html腳本標籤中包含.jsx?
index.html
:
<!doctype html>
<html>
<head>
...
</head>
<body>
<div id="root"></div>
</body>
</html>
然後index.jsx
:
import "babel-polyfill";
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(
<App />,
document.getElementById('root')
);
但如何JavaScript文件,甚至可以當運行index.jsx
index.html
中沒有腳本標籤?類似的東西:<script type="text/babel" src="./index.jsx">
?
我建議您使用Webpack將代碼轉換爲瀏覽器兼容代碼。你可以使用'HtmlWebpackPlugin'將注入的文件注入到你的index.html中。 – Baruch
這不能是整個應用程序。有沒有文件名爲'webpack.config.js'的機會?如果是這樣發佈它的內容,最有可能的是webpack捆綁器,負責採購腳本。是的,你必須在你的HTML中包含'.jsx'文件,但有更多的方法可以做到這一點,而不僅僅是使用'