Когда я запускаю npm run webpack
, все загружается без проблем, за исключением того, что я не вижу созданный код React. При переходе на localhost:3000
он говорит, что его не существует, и если бы я пошел по пути html, он по-прежнему не отображал jsx.
package.json
{
"name": "frontend",
"version": "1.0.0",
"description": "",
"main": "app.jsx",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"deploy": "webpack --mode production",
"watch": "webpack --mode development --watch"
},
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6"
},
"devDependencies": {
"@babel/core": "^7.5.4",
"@babel/preset-env": "^7.5.4",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.6",
"webpack": "4.35.3",
"webpack-cli": "^3.3.5",
"html-webpack-plugin": "^3.2.0"
},
"keywords": [],
"author": "",
"license": "ISC"
}
webpack.config.js
module.exports = (env, options) => ({
entry: {
app: "./assets/js/app.jsx"
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, './dist')
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
}
});
babel.config.js
module.exports = function (api) {
api.cache(true);
const presets = [
'@babel/preset-env',
'@babel/preset-react',
]
const plugins = [
]
return {
presets,
plugins
};
}
app.jsx
import React from 'react';
import ReactDOM from 'react-dom';
const App = ({ title }) =>
<div>{title}</div>
const title = "Hello World!"
document.addEventListener("DOMContentLoaded", () => {
ReactDOM.render(
<App title={title} />,
document.getElementById('root')
)
});