reactjs - 无法运行反应项目
问题描述
我是 reactjs 的新手。我正在尝试编写 webpack。
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './main.js',
output: {
path: path.join(__dirname, '/bundle'),
filename: 'index_bundle.js'
},
devServer: {
inline: true,
port: 3000
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
},
{
test: /\.scss$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader",
options: {
includePaths: ["absolute/path/a", "absolute/path/b"]
}
}]
}
]
},
plugins:[
new HtmlWebpackPlugin({
template: './index.html'
})
]
}
Html Webpack插件:错误:子编译失败:找不到入口模块:错误:无法解析'F:\ react-app'中的'F:\ react-app \ index.html':错误:无法解析' F:\react-app\index.html' in 'F:\react-app'
compiler.js:141 [react-app]/[html-webpack-plugin]/lib/compiler.js:141:18
Compiler.js:306 [react-app]/[webpack]/lib/Compiler.js:306:11
Compiler.js:631 [react-app]/[webpack]/lib/Compiler.js:631:15
Hook.js:154 AsyncSeriesHook.lazyCompileHook [react-app]/[tapable]/lib/Hook.js:154:20
Compiler.js:628 [react-app]/[webpack]/lib/Compiler.js:628:31
Hook.js:154 AsyncSeriesHook.lazyCompileHook [react-app]/[tapable]/lib/Hook.js:154:20
Compilation.js:1325 [react-app]/[webpack]/lib/Compilation.js:1325:35
解决方案
plugins:[
new HtmlWebpackPlugin({
hash:'true'
template: './index.html'
})
]
将 hash 设置为 true 并确保您拥有正确的模板文件位置。
推荐阅读
- python - Python:循环中的无限循环
- json - Circe derivedDecoder/deriveEncoder 找不到 io.circe.generic.encoding.DerivedAsObjectEncoder 类型的惰性隐式值
- asp.net-mvc - .NET Core 2.0 App - MVC 在调试时有效,但在 docker 容器中无效
- html - 包含元素底部的浮动图像
- c++ - 如何在对象库中部分公开对象内容?
- java - 在 Netbeans 中重新生成所有 Java Swing 页面的快速方法?
- javascript - 我的简单反应原生项目不会渲染,有什么建议吗?
- kubernetes - 有没有人尝试过 HLF 2.0 功能“外部构建器和启动器”并希望取得联系?
- kubernetes - 为什么我的服务不能将流量传递到 minikube 上具有命名端口的 pod?
- excel - 如何编写宏以将数据从多个组合框复制到工作表