【发布时间】:2021-08-03 03:57:11
【问题描述】:
我正在尝试使用workbox-webpack-plugin.InjectManifest,我发现的所有示例都类似于下面的代码,但我找不到src/sw.js 应该是什么样子的示例。我尝试搜索服务工作者文件的示例,并且觉得我可能正在开始一种追逐学习的方式,更多地了解我需要的服务工作者,而没有实际获得示例。我要做的就是将我的清单设置包含在我的服务人员中。考虑到函数的名称叫做 InjectManifest,我想我可以做到这一点
// Inside of webpack.config.js:
const {InjectManifest} = require('workbox-webpack-plugin');
module.exports = {
// Other webpack config...
plugins: [
// Other plugins...
new InjectManifest({
swSrc: './src/sw.js',
})
]
};
Manifest.js(额外,如果有用的话)
const Icon192 = require("../images/icon-192x192.png");
const Icon512 = require("../images/icon-512x512.png")
const manifest = {
icons: [
{
src: Icon192,
sizes: "192x192",
type: "image/png",
},
{
src: Icon512,
sizes: "512x512",
type: "image/png",
},
],
name: "My_App",
short_name: "My_App",
orientation: "portrait",
display: "standalone",
start_url: "/",
theme_color: " #228B22",
background_color: "#ffffff",
description: "Any Maskable",
start_url: "https://example.com",
display: "browser",
prefer_related_applications: false
};
module.exports = JSON.stringify(manifest, null, 2);
【问题讨论】:
标签: webpack service-worker manifest workbox workbox-webpack-plugin