Use the SSRed contents
This commit is contained in:
parent
cf98c0f082
commit
56a952fae0
4 changed files with 7 additions and 38 deletions
|
@ -17,7 +17,6 @@ import { generatePaginateFunction } from '../ssr/paginate.js';
|
|||
import { createRouteManifest, validateGetStaticPathsModule, validateGetStaticPathsResult } from '../ssr/routing.js';
|
||||
import { generateRssFunction } from '../ssr/rss.js';
|
||||
import { generateSitemap } from '../ssr/sitemap.js';
|
||||
import { createFetch } from './util.js';
|
||||
|
||||
export interface BuildOptions {
|
||||
mode?: string;
|
||||
|
@ -79,7 +78,6 @@ class AstroBuilder {
|
|||
debug(logging, 'build', timerMessage('Vite started', timer.viteStart));
|
||||
|
||||
timer.loadStart = performance.now();
|
||||
const fetch = createFetch(this.origin);
|
||||
const assets: Record<string, string> = {};
|
||||
const allPages: AllPagesData = {};
|
||||
// Collect all routes ahead-of-time, before we start the build.
|
||||
|
@ -189,7 +187,6 @@ class AstroBuilder {
|
|||
astroPageStyleMap,
|
||||
astroStyleMap,
|
||||
chunkToReferenceIdMap,
|
||||
fetch,
|
||||
pureCSSChunks,
|
||||
logging,
|
||||
origin,
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
import type { Response, RequestInit } from 'node-fetch';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
export type ViteFetch = (pathname: string, init?: RequestInit) => Promise<Response>;
|
||||
|
||||
function localizedFetch(origin: string, pathname: string, init?: RequestInit) {
|
||||
const url = origin + pathname;
|
||||
return fetch(url, init);
|
||||
}
|
||||
|
||||
export function createFetch(origin: string): ViteFetch {
|
||||
return localizedFetch.bind(null, origin);
|
||||
}
|
|
@ -3,12 +3,9 @@ import type { LogOptions } from '../core/logger';
|
|||
import type { ViteDevServer, Plugin as VitePlugin } from '../core/vite';
|
||||
import type { OutputChunk, PreRenderedChunk, RenderedChunk } from 'rollup';
|
||||
import type { AllPagesData } from '../core/build/types';
|
||||
import type { ViteFetch } from '../core/build/util';
|
||||
import type { RequestInit } from 'fetch';
|
||||
import parse5 from 'parse5';
|
||||
import srcsetParse from 'srcset-parse';
|
||||
import * as npath from 'path';
|
||||
import mime from 'mime';
|
||||
import { promises as fs } from 'fs';
|
||||
import { getAttribute, hasAttribute, insertBefore, remove, createScript, createElement, setAttribute } from '@web/parse5-utils';
|
||||
import { addRollupInput } from './add-rollup-input.js';
|
||||
|
@ -39,11 +36,10 @@ interface PluginOptions {
|
|||
origin: string;
|
||||
routeCache: RouteCache;
|
||||
viteServer: ViteDevServer;
|
||||
fetch: ViteFetch;
|
||||
}
|
||||
|
||||
export function rollupPluginAstroBuildHTML(options: PluginOptions): VitePlugin[] {
|
||||
const { astroConfig, astroStyleMap, astroPageStyleMap, chunkToReferenceIdMap, fetch, pureCSSChunks, logging, origin, allPages, routeCache, viteServer, pageNames } = options;
|
||||
const { astroConfig, astroStyleMap, astroPageStyleMap, chunkToReferenceIdMap, pureCSSChunks, logging, origin, allPages, routeCache, viteServer, pageNames } = options;
|
||||
|
||||
// The filepath root of the src folder
|
||||
const srcRoot = astroConfig.src.pathname;
|
||||
|
@ -468,18 +464,12 @@ export function rollupPluginAstroBuildHTML(options: PluginOptions): VitePlugin[]
|
|||
return null;
|
||||
},
|
||||
async load(id) {
|
||||
const init: RequestInit = {
|
||||
headers: {
|
||||
accept: mime.getType(id)
|
||||
}
|
||||
};
|
||||
|
||||
const res = await fetch(id, init);
|
||||
if(res.ok) {
|
||||
return await res.text();
|
||||
try {
|
||||
const mod = await viteServer.ssrLoadModule(id);
|
||||
return mod.default;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -9,12 +9,7 @@ describe('unocss', () => {
|
|||
fixture = await loadFixture({
|
||||
projectRoot: './fixtures/with-unocss/',
|
||||
});
|
||||
try {
|
||||
await fixture.build();
|
||||
} catch(err) {
|
||||
console.log('wha...', err);
|
||||
}
|
||||
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('Build when they create their own URLs', async () => {
|
||||
|
|
Loading…
Reference in a new issue