简体   繁体   English

在 React.js 2020 中运行 Webpack 配置时无法获取

[英]Cannot Get when running Webpack Config in React.js 2020

I run 'watch' to execute webpack dev sever "watch": "webpack-dev-server --progress"我运行 'watch' 来执行 webpack dev sever "watch": "webpack-dev-server --progress"

it compiles with no issues detected in terminal.它编译时没有在终端中检测到问题。 However, when i go to http://localhost:8080 , I receive an error message 'Cannot Get'但是,当我转到http://localhost:8080 时,收到错误消息“无法获取”

在此处输入图片说明

I've created a sandbox .我创建了一个沙箱

What I've tried so far adding writeToDisk: true in webpack.config.js and including loaders for svg "file-loader" and css "css-loader" which corrected another error i was having regarding not using a loader for css.到目前为止,我尝试在 webpack.config.js 中添加 writeToDisk: true 并包括用于 svg “file-loader” 和 css “css-loader” 的加载器,这纠正了我在不使用 css 加载器时遇到的另一个错误。 I've also tried changing the port to 3000. Not sure how relevant this is to solving this issue but i am using webstorm ide.我也尝试将端口更改为 3000。不确定这与解决此问题的相关性,但我正在使用 webstorm ide。

UPDATE:更新:

I fixed this issue by moving index.html and manifest.json in to the src folder.我通过将 index.html 和 manifest.json 移动到 src 文件夹来解决这个问题。

My question now is is there away to make this work without moving index.html and manifest into the same folder as webpack.config.js?我现在的问题是是否可以在不将 index.html 和 manifest 移动到与 webpack.config.js 相同的文件夹中的情况下完成这项工作? If possible i'd rather leave index.html and manifest in the public folder.如果可能,我宁愿将 index.html 和 manifest 留在公共文件夹中。

I'd suggest reading through webpack's documentation on Output Management .我建议通读 webpack 关于输出管理的文档。

To your question:对于你的问题:

My question now is is there away to make this work without moving index.html and manifest into the same folder as webpack.config.js?我现在的问题是是否可以在不将 index.html 和 manifest 移动到与 webpack.config.js 相同的文件夹中的情况下完成这项工作?

You can make this work using the official HtmlWebpackPlugin to generate your index.html file.你可以使用官方的HtmlWebpackPlugin来生成你的index.html文件。 You'll be able to point it at your own file, wherever you want it, and it will also let you scale your code eventually to generate the html file from a template.您将能够将它指向您自己的文件,无论您想要它的位置,并且它还可以让您最终扩展您的代码以从模板生成 html 文件。

    new HtmlWebpackPlugin({
      template: 'path/to/index.html'
    })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM