“npm 启动"如果公共文件夹在另一个文件夹中,则无法在 reactjs 中工作 [英] "npm start" not working in reactjs if public folder is inside another folder
问题描述
我的反应项目中有以下结构
I have the following structure in my react project
--project
|
--main
|
-- public
|
-- index.html
-- src
|
-- index.js
webpack.dev.config.js
webpack.prod.config.js
-- node_modules
-- package.json
对于上述结构,当我运行 npm start 时,出现以下错误
For the above structure, when I run npm start, I am getting below error
找不到所需的文件.名称:index.html 搜索于:C:\xampp\htdocs\project\public
Could not find a required file. Name: index.html Searched in: C:\xampp\htdocs\project\public
因为 public 文件夹位于 main 文件夹内.我怎样才能运行代码?请告诉我.
because the public folder is there inside main folder. How can I run the code? Please tell me.
编辑
output: {
filename: 'js/[name].js',
path: path.resolve('/main/public/'),
publicPath: '/main/public'
}
尝试在 webpack 中设置路径
tried setting the path in webpack
推荐答案
你应该改变 webpack.prod.config.js 中的公共路径:https://github.com/coryhouse/react-slingshot/blob/master/webpack.config.prod.js#L23
You should change the public path in webpack.prod.config.js: https://github.com/coryhouse/react-slingshot/blob/master/webpack.config.prod.js#L23
这篇关于“npm 启动"如果公共文件夹在另一个文件夹中,则无法在 reactjs 中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!