Generate Phoenix's cache manifest via webpack

Hello,

I’ve been using webpack to generate Phoenix’s cache_manifest.json for a while, and recently started to upgrade to 1.4. I ran into a slight hitch since my manifest doesn’t contain quite everything that phx.digest produces (it only contained the “latest” key). The reason seems to be this change introduced here: https://github.com/phoenixframework/phoenix/pull/3372/files

So I’ve fixed the problem it seems by putting in a minimal “digests” key, such that my cache_manifest now looks like:

{
  "latest": {
    ... snip
    "assets/admin.js": "assets/admin.4215f59c0adf2f5d59bd.js",
  },
  "digests": {
    ... snip
    "assets/admin.4215f59c0adf2f5d59bd.js": {
      "logical_path": "assets/admin.js"
    },
  }
}

It would be possible to generate the sha512 hash. but can someone help me understand what the sha512 hash is doing for the Phoenix.Config cache? Is it advisable to add this to the cache_manifest?

Thanks!

For reference, here’s how I’m producing the manifest:

    new ManifestPlugin({
      // this is where phoenix looks for the digest manifest
      // (see config/prod.exs)
      fileName: '../cache_manifest.json',

      // phoenix wants these values to be relative file paths
      // if we use the default output.publicPath, phooenix
      // constructs weird URLs
      publicPath: 'assets/',

      generate: (_seed, files) => ({
        // the 'latest' key here is what phoenix looks for: https://goo.gl/AYQkp3
        latest: files.reduce((latest, {name, path}) => ({
          ...latest,
          [`assets/${name}`]: path,
        }), {}),

        // phoenix 1.4 requires 'digests' as well: http://tinyurl.com/y5cffsjr
        digests: files.reduce((digests, {name, path}) => ({
          ...digests,
          [path]: {
            logical_path: `assets/${name}`,
          },
        }), {}),
      }),
    }),
2 Likes