我想创建PWA,但是http-server程序包不起作用。
因此,我使用ng new myProject
创建了一个默认的Angular-App,然后使用dist
创建了ng build --prod
文件夹
现在所有设置都已完成,因此我cd
进入dist
文件夹并运行npm软件包http-server -o
,第一个站点打开,我单击链接,但随后得到了很多错误消息。该站点仍然是空白(完全白色),应该有Angular CLI的Heroes-Demo。
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /styles.3ff695c00d717f2d2a11.css" Error (404): "Not found"
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /runtime-es2015.858f8dd898b75fe86926.js" Error (404): "Not found"
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /polyfills-es2015.27661dfa98f6332c27dc.js" Error (404): "Not found"
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /main-es2015.79588c7e85ca7a0dacf0.js" Error (404): "Not found"
所以我什至无法使网站正常工作,这可能是什么问题?
这是整个日志:
$ http-server -o
Starting up http-server, serving ./
Available on:
http://159.144.42.198:8080
http://192.168.34.113:8080
http://127.0.0.1:8080
Hit CTRL-C to stop the server
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /styles.3ff695c00d717f2d2a11.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /runtime-es2015.858f8dd898b75fe86926.js" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /polyfills-es2015.27661dfa98f6332c27dc.js" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /main-es2015.79588c7e85ca7a0dacf0.js" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /styles.3ff695c00d717f2d2a11.css" Error (404): "Not found"
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /runtime-es2015.858f8dd898b75fe86926.js" Error (404): "Not found"
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /polyfills-es2015.27661dfa98f6332c27dc.js" Error (404): "Not found"
[Wed Jul 03 2019 10:37:24 GMT+0200 (Central European Summer Time)] "GET /main-es2015.79588c7e85ca7a0dacf0.js" Error (404): "Not found"
答案 0 :(得分:0)
由于您的角度应用程序是SPA,因此您需要将每个请求重新路由到index.html
。
通过http-server
,您可以为其使用proxy参数,例如:
http-server --proxy http://localhost:8080?
http-server
README中也提到了它。