简体   繁体   English

从 Google 的 sw-toolbox 迁移到 Workbox SW (Visual Studio)

[英]Migrate from Google's sw-toolbox to Workbox SW (Visual Studio)

I used to use sw-toolbox for management of my service worker - small, simple, effective.我曾经使用sw-toolbox来管理我的 service worker - 小巧、简单、有效。 Now that Google have released Workbox SW (which replaces sw-toolbox and sw-precache) I need to migrate, but am battling to find:既然 Google 已经发布了Workbox SW (它取代了 sw-toolbox 和 sw-precache),我需要迁移,但我正在努力寻找:

a) single .js dependency for Workbox that I can include in my project a) 可以包含在我的项目中的 Workbox 的单个 .js 依赖项
b) a custom build tool to build a single .js dependency b) 用于构建单个 .js 依赖项的自定义构建工具
c) a way to include the Workbox build in my project build c) 一种在我的项目构建中包含 Workbox 构建的方法

Am I going about this the wrong way?我会以错误的方式解决这个问题吗?

Two useful references:两个有用的参考:
http://leruplund.dk/2017/04/15/setting-up-asp-net-core-in-visual-studio-2017-with-npm-webpack-and-typescript-part-i/ http://leruplund.dk/2017/04/15/setting-up-asp-net-core-in-visual-studio-2017-with-npm-webpack-and-typescript-part-i/
and
https://workboxjs.org/how_tos/workbox-cli.html https://workboxjs.org/how_tos/workbox-cli.html

Or just follow the 4 steps below或者只需按照以下 4 个步骤操作

Step 1: Install Node.js from https://nodejs.org/en/download/current/第 1 步:https://nodejs.org/en/download/current/安装 Node.js
Step 2: Initialize NPM on your project by opening command prompt on your project root and running the command npm init -y第 2 步:通过在项目根目录上打开命令提示符并运行命令npm init -y在项目上初始化 NPM
Step 3: From the same location at your command prompt, install Workbox with NPM by running the command npm install workbox-cli --global步骤 3:在命令提示符的同一位置,通过运行命令npm install workbox-cli --global安装带有 NPM 的npm install workbox-cli --global
Step 4: Generate a service worker by running the command workbox-cli generate:sw第 4 步:通过运行命令workbox-cli generate:sw生成 service worker

Having fiddled around a some hours, I was disappointed to note that the Workbox base dependency is 3x bigger than sw-toolbox - so, if size is critical to your project (which it often is for 3rd world market) then keep this in mind (sw-toolbox is 16kb, workbox is 48kb)摆弄了几个小时后,我很失望地注意到 Workbox 基础依赖项比 sw-toolbox 大 3 倍 - 因此,如果大小对您的项目至关重要(通常适用于第三世界市场),请记住这一点( sw-toolbox 为 16kb,workbox 为 48kb)

sw-toolbox works just fine for me at the moment, so I'm going to go back to it until I can work out how to get the size of Workbox a bit smaller. sw-toolbox 目前对我来说很好用,所以我会回到它,直到我能弄清楚如何让 Workbox 的大小变小一点。

However, I hope this helps someone else in the meantime :)但是,我希望这同时可以帮助其他人:)

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

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