- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我按照 https://developers.google.com/web/tools/workbox/guides/using-bundlers 中的步骤操作但是构建后的 dist/sw.js
文件根本没有被 Webpack 处理。所有导入语句仍然原封不动,注释没有被删除,也没有被 Terser 丑化。
我做错了什么?是否应该首先将 sw.js 构建为单独的条目,然后将输出传递给插件?
dist/sw.js(实际输出,除了注入(inject)的第一行之外没有任何内容被处理)
importScripts("/dist/precache-manifest.f26179340acee9ac29fc6c689e5cb0c5.js", "https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
/* global clients */
import { registerRoute } from 'workbox-routing'
import { CacheFirst, NetworkFirst } from 'workbox-strategies'
import { StaleWhileRevalidate } from 'workbox-strategies'
import { setConfig, skipWaiting, clientsClaim } from 'workbox-sw'
import { Plugin as BroadcastUpdatePlugin } from 'workbox-broadcast-update'
import { Plugin as ExpirationPlugin } from 'workbox-expiration'
import { Plugin as CacheableResponsePlugin } from 'workbox-cacheable-response'
./src/sw.js
/* global clients */
import { registerRoute } from 'workbox-routing'
import { CacheFirst, NetworkFirst } from 'workbox-strategies'
import { StaleWhileRevalidate } from 'workbox-strategies'
import { setConfig, skipWaiting, clientsClaim } from 'workbox-sw'
import { Plugin as BroadcastUpdatePlugin } from 'workbox-broadcast-update'
import { Plugin as ExpirationPlugin } from 'workbox-expiration'
import { Plugin as CacheableResponsePlugin } from 'workbox-cacheable-response'
webpack.common.js
module.exports = {
entry: {
main: './src/index.js',
},
output: {
path: path.join(__dirname, 'public', 'dist'),
publicPath: '/dist/',
filename: '[name].bundle.js'
},
module: {
rules: [
{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
plugins: [
new workboxPlugin.InjectManifest({
swSrc: './src/sw.js',
swDest: 'sw.js'
})
]
}
webpack.prod.config.js
module.exports = merge(common, {
devtool: 'nosources-source-map',
stats: {
chunkModules: true,
// Examine all modules
maxModules: Infinity,
// Display bailout reasons
optimizationBailout: false
},
plugins: [new CleanWebpackPlugin({ verbose: true })],
optimization: {
// Use terser instead of the default Uglify since service
// worker code does not need to be transpiled to ES5.
minimizer: [
new Terser({
// Ensure .mjs files get included.
test: /\.m?js$/
})
]
}
})
Github 上的相关问题:https://github.com/GoogleChrome/workbox/issues/1513
最佳答案
We are actively working on a rewrite for the InjectManifest plugin that will perform a webpack child compilation on swSrc, in addition to populate the precache manifest.
https://github.com/GoogleChrome/workbox/issues/1513#issuecomment-506482323
关于webpack - 如何让 workboxPlugin.InjectManifest 与 Webpack 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56710951/
我按照 https://developers.google.com/web/tools/workbox/guides/using-bundlers 中的步骤操作但是构建后的 dist/sw.js 文件
我是一名优秀的程序员,十分优秀!