当サイトの、
upgrade で
前提
- npm outdated の
実行結果
以下になります。 $ npm outdated
Package Current Wanted Latest Location jquery 2.2.4 2.2.4 3.3.1 clean_blog_frontend workbox-broadcast-cache-update 2.1.3 2.1.3 3.6.3 clean_blog_frontend workbox-webpack-plugin 2.1.3 2.1.3 4.1.1 clean_blog_frontend
jquery
は使用している CMS 都合で バージョン UP が 難しいため、 放置しています。
workbox-broadcast-cache-update
、workbox-webpack-plugin
をUpgrade します。
workbox-broadcast-cache-update
Migrate from Workbox v3 to v4 | Workbox | Google Developers に、workbox-broadcast-cache-update
は
Uninstall、workbox-broadcast-update
に
npm uninstall workbox-broadcast-cache-update npm install workbox-broadcast-update
workbox-webpack-plugin
Migrate from Workbox v3 to v4 | Workbox | Google Developers に
The naming of some options that can be passed in to either workbox-cli, workbox-build, or workbox-webpack-plugin has changed. Whenever >”Url” was used in an option name, it’s been deprecated in favor of “URL”. This means that the following option names are preferred:
dontCacheBustURLsMatching ignoreURLParametersMatching modifyURLPrefix templatedURLs The “Url” variation of those option names still works in v4, but will result in a warning message. We encourage developers to migrate in >advance of the v5 release.
Url
関連のwebpack.config.js
周辺が
面倒なので、
npm uninstall workbox-webpack-plugin npm install workbox-webpack-plugin
エラー対処
build
時に
TypeError: WorkboxPlugin is not a constructor
これは、
* webpack - new WorkboxPlugin({ TypeError: WorkboxPlugin is not a constructor - Stack Overflow
* workbox-webpack-plugin を
v2 > v3
の
ValidationError: “swSrc” is not a supported parameter.
続いて、
ValidationError: "swSrc" is not a supported parameter.
InjectManifest
をGenerateSW
をv2
は、WorkboxPlugin
でInjectManifest
、GenerateSW
双方のこの
GenerateSW
ではなく、InjectManifest
にInjectManifest
にWARING への 対処
続いて、
In Workbox v3 and later, this is usually not needed
WARNING in You're using the following Workbox configuration options: [globDirectory, globIgnores, globPatterns]. In Workbox v3 and later, this is usually not needed. Please see https://goo.gl/EQ4Rhm for more info.
workbox-webpack-plugin を
WARNING in The ‘modifyUrlPrefix’ option has been renamed to ‘modifyURLPrefix’.
警告の
WARNING in The 'modifyUrlPrefix' option has been renamed to 'modifyURLPrefix'. Please update your config. 'modifyUrlPrefix' is now deprecated and will be removed in a future release of Workbox.
modifyUrlPrefix
が、modifyURLPrefix
に
名称を
WARNING in You're using the following Workbox configuration options: [modifyURLPrefix]. This will not have any effect, as it will only modify files that are matched via 'globPatterns'. You can remove them from your config, and learn more at https://goo.gl/EQ4Rhm
modifyURLPrefix のglobPatterns
に
modifyURLPrefix: { 'webpack_bundles': 'static/webpack_bundles', 'js': 'static/js', },
プログラム実装上の 修正箇所
以下は、
workbox-sw.prod.v2.1.3.js
の 読み込みを 削除
InjectManifest で、
importScripts("static/webpack_bundles/precache-manifest.c8fbe3b8d6065422a95f9542633599ab.js", "https://storage.googleapis.com/workbox-cdn/releases/4.1.1/workbox-sw.js");
もともと
importScripts('static/js/workbox-sw.prod.v2.1.3.js');
ServiceWorker の 実装の 変更 precache > precacheAndRoute
InjectManifest
モードで、
/* eslint-disable no-undef */ const workboxSW = new WorkboxSW(); workboxSW.precache([]); /* eslint-enable no-undef */
以下のself.__precacheManifest
に
workbox.precaching.precacheAndRoute(self.__precacheManifest || []);
serviceWorker.js:7 Uncaught TypeError: Cannot read property ‘registerRoute’ of undefined
Migrate from Workbox v2 to v3 | Workbox | Google Developers
v2 からworkbox.router.registerRoute
は、workbox.routing.registerRoute
と
古い
Public path を 追加した
precache-manifest でpublicPath
を
output: { path: cleanBlogRoot + "/static/webpack_bundles", filename: "[name]-[hash].js", crossOriginLoading: 'anonymous', publicPath: "/static/webpack_bundles/" },
Upgrade 後の workbox の バージョン
4.1.1
に
npm list --depth 0 | grep workbox ├── workbox-broadcast-update@4.1.1 └── workbox-webpack-plugin@4.1.1
参考
以下、
以上です。
コメント