[英]Angular + Firebase hosting: how to use static js file in website root?
I'm making PWA with Angular and Firebase.我正在使用 Angular 和 Firebase 制作 PWA。 Using StackBlitz for developing.
使用 StackBlitz 进行开发。
I want to make "Add to home screen" Chrome standard advice working when user opens my app in browser, but I can't correctly call "service worker" JS from my code...当用户在浏览器中打开我的应用程序时,我想让“添加到主屏幕”Chrome 标准建议起作用,但我无法从我的代码中正确调用“服务工作者”JS ...
I created sw.js in /src folder of my project.我在项目的 /src 文件夹中创建了 sw.js。 I've added it to 'scripts' and 'assets' sections in.angular-cli.json and.angular.json.
我已将其添加到 .angular-cli.json 和 .angular.json 中的“脚本”和“资产”部分。 And in StackBlitz everything works fine!
在 StackBlitz 中一切正常!
But when I deploy project to Firebase (using Stackblitz build-in functionality) nothing works... Seems like server doesn't see the file in expected dir (/src/sw.js)... Did anybody face same problem?但是,当我将项目部署到 Firebase(使用 Stackblitz 内置功能)时,没有任何效果......似乎服务器在预期的目录(/src/sw.js)中看不到文件......有人遇到同样的问题吗?
I don't think there's a way to fix it, I'm pretty sure the problem is the stackblitz server.我认为没有办法解决它,我很确定问题出在 stackblitz 服务器上。 but luckily firebase engineers made a simple node script to replace a single file.
但幸运的是 firebase 工程师制作了一个简单的节点脚本来替换单个文件。 It worked for me.
它对我有用。 As the link describes just install git, and node, and then in command prompt run these commands: git
如链接所述,只需安装 git 和节点,然后在命令提示符下运行以下命令:git
additional info:附加信息:
I tried replicating your problem, let me know if the link works.我尝试复制您的问题,如果链接有效,请告诉我。 https://stackblitz.com/edit/angular-epvm8w .
https://stackblitz.com/edit/angular-epvm8w 。 Basically just in index.html.
基本上就在 index.html 中。 the js file just has alert("alert");
js 文件只有 alert("alert"); in it.
在里面。 it works like you said but when deployed i think the stackblitz server is replacing the content with html.
它像你说的那样工作,但部署时我认为 stackblitz 服务器正在用 html 替换内容。 I think this because in chrome developers panel under sources the js file had the same html as the index template from stackblitz's github.
我认为这是因为在源代码下的 chrome 开发人员面板中,js 文件与来自 stackblitz 的 github 的索引模板具有相同的 html。 Makes me think it's just a bug.
让我觉得这只是一个错误。 same thing happened to a css file.
css 文件也发生了同样的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.