You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改workbox-webpack-plugin中precacheManifest的生成目录?

Adjusting Precache Manifest Output Directory in Workbox 3.0

Absolutely! You can definitely adjust the output directory of the precache-manifest.[hash].js file in Workbox 3.0 by tweaking your workbox-webpack-plugin configuration. Here's how to handle it based on which plugin you're using:

Using GenerateSW Plugin (Auto-generated Service Worker)

If you're using the GenerateSW plugin (the most common setup for auto-generating a Service Worker), you just need to add the manifestFilename option to your plugin configuration. This lets you specify the path (relative to your webpack output.path) where the manifest file should be saved.

For example, if your webpack output.path is set to dist, updating your config like this will output the manifest to dist/static/precache-manifest.[hash].js:

const { GenerateSW } = require('workbox-webpack-plugin');

module.exports = {
  // Your existing webpack configuration (entry, output, etc.)
  plugins: [
    new GenerateSW({
      // Add this line to set the manifest path
      manifestFilename: 'static/precache-manifest.[hash].js',
      // Your other Workbox config options (e.g., swDest, skipWaiting, etc.)
    })
  ]
};

Workbox will automatically handle updating the Service Worker's reference to the manifest file, so you don't need to modify any Service Worker code manually.

Using InjectManifest Plugin (Custom Service Worker)

If you're using a custom Service Worker with the InjectManifest plugin, you'll need two adjustments:

  1. Set the manifestFilename option in the plugin config (same as above) to output the manifest to dist/static/.
  2. Update the importScripts call in your custom Service Worker to point to the new path of the manifest file. For example:
// In your custom service-worker.js file
importScripts('./static/precache-manifest.[hash].js');

Workbox will replace the [hash] placeholder with the actual hash during the build process, so the path will resolve correctly.

Just make sure your webpack output.path is configured to dist (which matches your current setup), and the above changes will put the precache manifest exactly where you want it.

内容的提问来源于stack exchange,提问作者mazipan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:30:00