[dotcom] Delete service worker, cache tldraw assets (#2552)
A few things happening here - Delete our service worker. Turns out that a couple of years back browsers decided that a service worker is no longer required for a PWA so you can just have the manifest and still install on the user's device. - Cache tldraw's assets as part of the dotcom vite asset pipeline. This allows them to participate in the asset coalescing (preserving old versions of asset files so old clients don't stop working when you deploy new versions of things, see https://github.com/tldraw/brivate/pull/3132 for more context). - Add a new 'imports.vite.js' file to the assets package, because we import a bunch of json translation files, and vite imports .json files as parsed json objects instead of string urls, and there's no good way to tell it not to. Even if there was we wouldn't want to impose that config on our users. So another way to tell vite to load any asset as a url string is to append `?url` to the end of the import path. That's what this file does. closes [#2486](https://github.com/tldraw/tldraw/issues/2486) ### Change Type - [x] `minor` — New feature [^1]: publishes a `patch` release, for devDependencies use `internal` [^2]: will not publish a new version ### Release Notes - Fix 'could not load assets' error that we often see on tldraw.com after a deploy
This commit is contained in:
parent
be927df935
commit
ade38247d8
16 changed files with 581 additions and 704 deletions
|
@ -298,7 +298,10 @@ async function writeUrlBasedAssetDeclarationFile() {
|
|||
await writeCodeFile('scripts/refresh-assets.ts', 'javascript', codeFilePath, codeFile)
|
||||
}
|
||||
|
||||
async function writeImportBasedAssetDeclarationFile(): Promise<void> {
|
||||
async function writeImportBasedAssetDeclarationFile(
|
||||
importSuffix: string,
|
||||
fileName: string
|
||||
): Promise<void> {
|
||||
let imports = `
|
||||
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
||||
/// <reference path="./modules.d.ts" />
|
||||
|
@ -322,7 +325,7 @@ async function writeImportBasedAssetDeclarationFile(): Promise<void> {
|
|||
.replace(/[^a-zA-Z0-9_]/g, '_')
|
||||
.replace(/_+/g, '_')
|
||||
.replace(/_(.)/g, (_, letter) => letter.toUpperCase())
|
||||
imports += `import ${variableName} from ${JSON.stringify('./' + href)};\n`
|
||||
imports += `import ${variableName} from ${JSON.stringify('./' + href + importSuffix)};\n`
|
||||
declarations += `${JSON.stringify(name)}: formatAssetUrl(${variableName}, opts),\n`
|
||||
}
|
||||
declarations += '},\n'
|
||||
|
@ -333,7 +336,7 @@ async function writeImportBasedAssetDeclarationFile(): Promise<void> {
|
|||
}
|
||||
`
|
||||
|
||||
const codeFilePath = join(REPO_ROOT, 'packages', 'assets', 'imports.js')
|
||||
const codeFilePath = join(REPO_ROOT, 'packages', 'assets', fileName)
|
||||
await writeCodeFile(
|
||||
'scripts/refresh-assets.ts',
|
||||
'javascript',
|
||||
|
@ -408,7 +411,8 @@ async function main() {
|
|||
nicelog('Writing asset declaration file...')
|
||||
await writeAssetDeclarationDTSFile()
|
||||
await writeUrlBasedAssetDeclarationFile()
|
||||
await writeImportBasedAssetDeclarationFile()
|
||||
await writeImportBasedAssetDeclarationFile('', 'imports.js')
|
||||
await writeImportBasedAssetDeclarationFile('?url', 'imports.vite.js')
|
||||
await writeSelfHostedAssetDeclarationFile()
|
||||
nicelog('Done!')
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue