Skip to content

Commit

Permalink
feat: change quasarConfig cache way
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwa committed Aug 11, 2023
1 parent 3681855 commit e40d05f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ import {
} from '@vercel/build-utils';

import type { Route } from '@vercel/routing-utils';
import type { Context } from '.';

interface BuilderOutput {
watch?: string[];
output: Record<string, Lambda | File | FileFsRef>;
routes: Route[];
}

export async function build(opts: BuildOptions): Promise<BuilderOutput> {
export async function build(
opts: BuildOptions,
context: Context
): Promise<BuilderOutput> {
const { files, entrypoint, workPath, config = {}, meta = {} } = opts;

consola.log(`use vercel-quasar@${require('../package.json').version}`);
Expand Down Expand Up @@ -156,8 +160,8 @@ export async function build(opts: BuildOptions): Promise<BuilderOutput> {
const quasarConfigName = 'quasar.config.js';
const quasarConfig = getQuasarConfig(entrypointPath);

// cache quasarConfig to vercel config
config.quasarConfig = quasarConfig;
// cache quasarConfig to global context
context.quasarConfig = quasarConfig;

consola.log('load quasar config', quasarConfig);

Expand Down
19 changes: 17 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { BuildOptions, PrepareCacheOptions } from '@vercel/build-utils/dist';
import { build } from './build';
import config from './config';
import prepareCache from './prepare-cache';
import { QuasarConfiguration } from './utils';

export interface Context {
quasarConfig?: QuasarConfiguration;
}

let context: Context = {
quasarConfig: undefined,
};

module.exports = {
version: 2,
build,
build: (options: BuildOptions) => {
return build(options, context);
},
config,
prepareCache,
prepareCache: (options: PrepareCacheOptions) => {
return prepareCache(options, context);
},
};
12 changes: 6 additions & 6 deletions src/prepare-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import consola from 'consola';
import { startStep, endStep } from './utils';
import { PrepareCacheOptions, glob, Files } from '@vercel/build-utils';

import type { QuasarConfiguration } from './utils';
import type { Context } from '.';

async function prepareCache({
workPath,
config,
}: PrepareCacheOptions): Promise<Files> {
async function prepareCache(
{ workPath }: PrepareCacheOptions,
context: Context
): Promise<Files> {
startStep('Collect cache');

const quasarConfig = config.quasarConfig as QuasarConfiguration;
const quasarConfig = context.quasarConfig!;
console.log('quasarConfig', quasarConfig);
let distDir = quasarConfig?.build?.distDir || 'dist/ssr';

Expand Down

0 comments on commit e40d05f

Please sign in to comment.