我正在为 React Web 应用程序设置样板,并在导航到http://localhost:3000. 我是一个新的训练营学生,我对 webpack 配置的了解非常浅,尤其是有很多依赖项/babel 设置在起作用。我查看了对发布此问题的其他用户的回复,但似乎它可能是由围绕 webpack 配置的任何数量的问题引起的,而且我担心在时间紧迫的情况下会进一步破坏事情。
所以我在下面发布了我的一些代码。我很困惑-感谢您的指点!
公共/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>-= PROJECT TITLE PLACEHOLDER =-</title>
<script src="/bundle.js" defer></script>
</head>
<body>
<div id="app"></div>
</body>
</html>
应用程序/ index.js
import '../public/style.css'
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import store from './redux'
import Users from './components/Users'
ReactDOM.render(
<Provider store={store}>
<Users />
</Provider>,
document.getElementById('app')
)
webpack.config.js
'use strict'
const { resolve } = require('path')
module.exports = {
entry: ['babel-polyfill', './app/index'],
output: {
path: __dirname,
filename: './public/bundle.js'
},
mode: 'development',
context: __dirname,
devtool: 'source-map',
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
test: /jsx?$/,
include: resolve(__dirname, './app'),
loader: 'babel-loader',
options: {
presets: ['react']
}
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
}
}
慕莱坞森
杨魅力
三国纷争
相关分类