Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

add __STATIC_CONTENT_MANIFEST as a text module for modules workers #2126

Merged
merged 3 commits into from
Nov 8, 2021

Conversation

g45t345rt
Copy link
Contributor

@g45t345rt g45t345rt commented Nov 5, 2021

The __STATIC_CONTENT_MANIFEST is not accessible when using modules workers [sites]

This pr makes it possible to import the content of manifest as text.

It is also in favor of storing the manifest in vars
#2114

Here is how to get the content

import manifest from '__STATIC_CONTENT_MANIFEST'

export default {
  fetch(request, env, ctx) {
    console.log(JSON.parse(manifest))
  }
}

If you are developing with Miniflare you need

new Miniflare({
  modulesRules: [{ type: 'Text', include: ['__STATIC_CONTENT_MANIFEST'] }],
  ...
})

or

miniflare --modules-rule "Text=__STATIC_CONTENT_MANIFEST"

You also have to create a file named __STATIC_CONTENT_MANIFEST in /dist

Plus if you are using TS you have to declare the module like this

declare module '__STATIC_CONTENT_MANIFEST' {
  const manifest: string
  export default manifest
}

It's kind of pain to setup if you are developing locally...

Related issues
#1938
#1973

@threepointone
Copy link
Contributor

cc @mrbbot can we automate this module creation for miniflare?

@mrbbot
Copy link
Contributor

mrbbot commented Nov 5, 2021

Yep, for sure. Is this not something that should be in env though? This is what Miniflare does at the moment (https://github.com/cloudflare/miniflare/blob/5d325870a78ad295bf2eb74b0abec333c444f2c9/packages/sites/src/plugin.ts#L72).

How does it work for service-worker format workers? Wouldn't all text bindings be included in env?

@mrbbot
Copy link
Contributor

mrbbot commented Nov 5, 2021

To be fair though, Miniflare always uses an empty object for __STATIC_CONTENT_MANIFEST to disable edge caching, so it would be really easy to set this as a module.

Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Landing this. We'll likely have to do a release of kv-asset-handler as well so the globals don't break the runtime.

@threepointone threepointone merged commit 5e8ba9d into cloudflare:master Nov 8, 2021
@nataliescottdavidson nataliescottdavidson mentioned this pull request Nov 9, 2021
mrbbot added a commit to cloudflare/miniflare that referenced this pull request Nov 11, 2021
mrbbot added a commit to cloudflare/miniflare that referenced this pull request Jan 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants