在Cordova中使用Webpack时出现“找不到文件"错误 [英] 'Files not found' error when using Webpack in Cordova
问题描述
我正在尝试使用Webpack和Cordova构建应用程序. 我将webpack的"dist"文件夹中的内容放入cordova的"www"文件夹中,然后为Android构建它并进行仿真.
I'm trying to build an app using Webpack and Cordova. I put the contents of my webpack 'dist' folder into my cordova 'www' folder and then I build it for Android and emulate it.
打开应用程序时,出现很多"ERR_FILE_NOT_FOUND"错误,当我打开编译的index.html时,我看到每个链接前面都有一个"/",这会导致错误,因为它指向错误的目录.
When the app opens I get a lot of 'ERR_FILE_NOT_FOUND' erros, when I open my compiled index.html I see that there is a '/' in front of every link that causes the error because it points to the wrong directory.
示例 'src =/static/js/example.js'
如果我手动删除第一个'/'并重建适用于Android的应用程序,则它将正常工作.
If I remove the first '/' manually and rebuild the app for Android it works.
在编译项目时如何删除那些'/',这样在编译后不必手动编辑每个链接?
How do I remove those '/' when I compile my project so I don't have to manually edit every link after compiling?
示例:
它应该在与index.html相同的文件夹中查找文件:"file:///android_asset/www/index.html#/"
It should look for the files in the same folder as the index.html: "file:///android_asset/www/index.html#/"
相反,它转到: 'file:///static/js/example.js'
instead it goes to: 'file:///static/js/example.js'
(静态地图与index.html位于同一目录中)
(The static map is in the same directory as the index.html)
注意:当我直接在浏览器中打开index.html时,链接会起作用
Note: When I open the index.html directly in the browser the links work
推荐答案
在Webpack配置中添加publicPath: ''
似乎已解决了该问题!
Adding publicPath: ''
to the webpack config seemed to have resolved the issue!
这篇关于在Cordova中使用Webpack时出现“找不到文件"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!