Skip to content

Commit

Permalink
ViteBuildManifest and note about import-attributes (#8818)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Jul 4, 2023
1 parent a471d26 commit 8b85ad6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
21 changes: 19 additions & 2 deletions packages/vite/src/buildFeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs/promises'
import path from 'path'

import { build as esbuildBuild, PluginBuild } from 'esbuild'
import type { Manifest as ViteManifest } from 'vite'
import type { Manifest as ViteBuildManifest } from 'vite'

import { getRouteHookBabelPlugins } from '@redwoodjs/internal'
import { transformWithBabel } from '@redwoodjs/internal/dist/build/babel/api'
Expand Down Expand Up @@ -96,9 +96,26 @@ export const buildFeServer = async ({ verbose }: BuildOptions) => {
})

// Step 3: Generate route-manifest.json

// TODO When https://github.com/tc39/proposal-import-attributes and
// https://github.com/microsoft/TypeScript/issues/53656 have both landed we
// should try to do this instead:
// const clientBuildManifest: ViteBuildManifest = await import(
// path.join(getPaths().web.dist, 'build-manifest.json'),
// { with: { type: 'json' } }
// )
// NOTES:
// * There's a related babel plugin here
// https://babeljs.io/docs/babel-plugin-syntax-import-attributes
// * Included in `preset-env` if you set `shippedProposals: true`
// * We had this before, but with `assert` instead of `with`. We really
// should be using `with`. See motivation in issues linked above.
// * With `assert` and `@babel/plugin-syntax-import-assertions` the
// code compiled and ran properly, but Jest tests failed, complaining
// about the syntax.
const manifestPath = path.join(getPaths().web.dist, 'build-manifest.json')
const buildManifestStr = await fs.readFile(manifestPath, 'utf-8')
const clientBuildManifest: ViteManifest = JSON.parse(buildManifestStr)
const clientBuildManifest: ViteBuildManifest = JSON.parse(buildManifestStr)

const routesList = getProjectRoutes()

Expand Down
20 changes: 18 additions & 2 deletions packages/vite/src/runFeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import express from 'express'
import { createProxyMiddleware } from 'http-proxy-middleware'
import isbot from 'isbot'
import { renderToPipeableStream } from 'react-dom/server'
import type { Manifest as ViteManifest } from 'vite'
import type { Manifest as ViteBuildManifest } from 'vite'

import { getConfig, getPaths } from '@redwoodjs/project-config'
import { matchPath } from '@redwoodjs/router'
Expand Down Expand Up @@ -50,12 +50,28 @@ export async function runFeServer() {
const rwPaths = getPaths()
const rwConfig = getConfig()

// TODO When https://github.com/tc39/proposal-import-attributes and
// https://github.com/microsoft/TypeScript/issues/53656 have both landed we
// should try to do this instead:
// const routeManifest: RWRouteManifest = await import(
// rwPaths.web.routeManifest, { with: { type: 'json' } }
// )
// NOTES:
// * There's a related babel plugin here
// https://babeljs.io/docs/babel-plugin-syntax-import-attributes
// * Included in `preset-env` if you set `shippedProposals: true`
// * We had this before, but with `assert` instead of `with`. We really
// should be using `with`. See motivation in issues linked above.
// * With `assert` and `@babel/plugin-syntax-import-assertions` the
// code compiled and ran properly, but Jest tests failed, complaining
// about the syntax.
const routeManifestStr = await fs.readFile(rwPaths.web.routeManifest, 'utf-8')
const routeManifest: RWRouteManifest = JSON.parse(routeManifestStr)

// TODO See above about using `import { with: { type: 'json' } }` instead
const manifestPath = path.join(getPaths().web.dist, 'build-manifest.json')
const buildManifestStr = await fs.readFile(manifestPath, 'utf-8')
const buildManifest: ViteManifest = JSON.parse(buildManifestStr)
const buildManifest: ViteBuildManifest = JSON.parse(buildManifestStr)

const indexEntry = Object.values(buildManifest).find((manifestItem) => {
return manifestItem.isEntry
Expand Down

0 comments on commit 8b85ad6

Please sign in to comment.