Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workbox-webpack-plugin v5 interface #1591

Closed
jeffposnick opened this issue Jul 27, 2018 · 8 comments
Closed

workbox-webpack-plugin v5 interface #1591

jeffposnick opened this issue Jul 27, 2018 · 8 comments
Labels
Breaking Change Denotes a "major" semver change. Discuss An open question, where input from the community would be appreciated. workbox-webpack-plugin
Milestone

Comments

@jeffposnick
Copy link
Contributor

jeffposnick commented Jul 27, 2018

Background

The team is planning on addressing the various issues and pain points raised against the workbox-webpack-plugin with a number of breaking changes to the interface and behavior in an upcoming v4.0.0 release.

We're looking to gather feedback from the community prior to starting on the implementation, so please feel free to reply if you've got any concerns.

Open issues

These are categorized, but not prioritized, based on the open issues. It gives a good overview of the general areas in which feedback has been concentrated.

We won't be able to address all of these issues in the initial v4.0.0 release. Our goal is to address many of them that require an incompatible API surface or a significant change in behavior in at once, to minimize the number of major releases with breaking changes.

Filesystem paths

URL paths

Asset pipeline

Parity with "glob" configuration

Developer experience

Proposed v5 plugin interface

This interface will apply to both InjectManifest and GenerateSW. (swSrc is the only option that's limited to InjectManifest.)

I'll keep this example up-to-date as folks add feedback to the issue thread.

new InjectManifest or GenerateSW ({
  // Same as in v3:
  swDest,
  importWorkboxFrom,
  importsDirectory,
  precacheManifestFilename,
  skipWaiting,
  clientsClaim,
  runtimeCaching,
  navigateFallback,
  navigateFallbackBlacklist,
  navigateFallbackWhitelist,
  importScripts,
  ignoreUrlParametersMatching,
  directoryIndex,
  cacheId,
  maximumFileSizeToCacheInBytes,
  // InjectManifest only:
  swSrc,

  // Newly changed in v4:
  webpackAssets: {
    // Moved to be under a webpackAssets parent:
    chunks,
    excludeChunks,
    include,
    exclude,

    // The next two are the same as the v3 options,
    // but now only apply to webpack assets.
    modifyUrlPrefix,
    manifestTransforms,

    // Maps a static URL to one or more webpack assets. E.g.
    // {
    //   '/shell': {
    //     chunks: ['chunk1'],
    //     include: [/*.js/],
    //   }
    // }
    templatedUrls,

    // Array defaulting to ['[hash]'].
    // You can add any RegExp, or options along the lines of
    // https://github.com/webpack/loader-utils#interpolatename
    dontCacheBustUrlsMatching,
  },

  fileSystemAssets: {
    // Same as in v3, but moved to be under a fileSystemAssets parent.
    globDirectory,
    globFollow,
    globIgnores,
    globPatterns,
    globStrict,

    // The next four behave the same as the v3 options,
    // but explicitly only apply to file system assets.
    modifyUrlPrefix,
    manifestTransforms,
    templatedUrls,
    dontCacheBustUrlsMatching,
  },

  // Removed as top-level options in v4:
  /*
    dontCacheBustUrlsMatching,
    templatedUrls,
    globDirectory,
    globFollow,
    globIgnores,
    globPatterns,
    globStrict,
    modifyUrlPrefix,
    manifestTransforms,
    chunks,
    excludeChunks,
    include,
    exclude,
  */
});
@jeffposnick jeffposnick added Discuss An open question, where input from the community would be appreciated. Breaking Change Denotes a "major" semver change. workbox-webpack-plugin labels Jul 27, 2018
@piehei
Copy link

piehei commented Jul 27, 2018

Hmm. Not sure what I should be looking for.

Is some functionality going to be removed? Or is this """just""" an API breaking change?

@jeffposnick
Copy link
Contributor Author

There's some new functionality (making it so that options like manifestTransforms and templatedUrls can apply to webpack assets) as well as breaking changes (moving the top-level options like templatedUrls, etc. so that they're sub-options of either fileSystemAssets or webpackAssets).

It's a combination of the new interface (any naming concerns, etc.) along with the list of issues that are on our radar that we're looking for feedback on.

@developit
Copy link

webpackAssets is a welcome addition Jeff!

@joaovieira
Copy link

joaovieira commented Aug 24, 2018

Yes! Just came to the issues to "complain" about the fact modifyUrlPrefix, manifestTransforms and dontCacheBustUrlsMatching only run on glob assets, so I'm very pleased to see this!

Here's my use case. Following is a simplified Next.js precache manifest (based on the webpack emitted files):

self.__precacheManifest = [
  {
    "revision": "29c0a6405b762b2ed86f",
    "url": "static/style-3518e9dc77a50a7a733511fc53c5f981.css"
  },
  {
    "url": "static/commons/main-29c0a6405b762b2ed86f.js"
  },
  {
    "revision": "8d205d627155bcada52d",
    "url": "bundles/pages/signin.js"
  },
  {
    "revision": "7df5921f82befca27ca2",
    "url": "bundles/pages/index.js"
  },
  {
    "revision": "cd541d001d7a4e98c326",
    "url": "bundles/pages/_error.js"
  },
  {
    "revision": "f254703bdcbdcd928292",
    "url": "bundles/pages/_app.js"
  },
  {
    "revision": "88201f6df194e5ca3129373100147939",
    "url": "build-manifest.json"
  }
];

Problem 1:

As you see, some of the assets are already hashed, so I'd like to not revision those. Some others are not hashed at build time, but are served/exported with a hash in the url. E.g. bundles/pages/index.js is served as _next/ad684ad8-91d3-4809-bd83-0039c7d22a3e/page/index.js. As such, I'd like to use:

dontCacheBustUrlsMatching: /$(bundles\/pages|static)/

Problem 2:

As hinted above, files are served on different paths than their location in the filesystem. E.g. the static folder is served as _next/static. As such, I'd like to use:

modifyUrlPrefix: {
  'bundles/pages': join(assetPrefix, `/_next/${buildId}/page`),
   chunks: join(assetPrefix, '/_next/webpack/chunks'),
   static: join(assetPrefix, '/_next/static'),
}

Problem 3 and 4:

build-manifest.json is emitted but it's not even served and does not need to be in the precache manifest. I'd like to filter it out.

I want to use the Next.js buildId as the revision number for every revisioned entry.

As such, I'd like to use:

manifestTransforms: [
  originalManifest => {
    const manifest = originalManifest
      .filter(entry => entry.url !== 'build-manifest.json')
      .map(({ url, revision }) => ({ url, revision: revision && buildId }));
    return { manifest };
  },
]

This seemed a very reasonable use case and was happy to see workbox supported all these options, until I found out the webpack plugin didn't :)

Hope this helps.

@zoellner
Copy link

Came here after looking at #1513
Can you explain a bit how this is going to resolve that issue? I.e. how can I have a src/sw/main.js file that let's say is using a whole bunch of imports and is currently being compiled with a separate process to .tmp/sw.js to be the swSrc without the separate compile process?

@jeffposnick
Copy link
Contributor Author

After chatting with @developit a bit, we might end up going with an approach that eliminated the fileSystemAssets set of config options entirely, and relied on folks using https://github.com/webpack-contrib/copy-webpack-plugin (potentially with emit turned off) to pull in assets that wouldn't "normally" be part of their webpack asset pipeline.

We wanted to float that idea here and see if there were strong feelings one way or another.

@jeffposnick
Copy link
Contributor Author

Interested parties who have been following this issue should take a look at @developit's proposal, detailed at #1854, which addresses a few of the issues outlined in this meta-issue.

@jeffposnick
Copy link
Contributor Author

This should be addressed by the current Workbox v5.0.0 alpha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change Denotes a "major" semver change. Discuss An open question, where input from the community would be appreciated. workbox-webpack-plugin
Projects
None yet
Development

No branches or pull requests

5 participants