@metricinsights/pp-dev
Version:
Portal Page dev build tool
126 lines (121 loc) • 3.78 kB
TypeScript
import { InlineConfig } from 'vite';
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer';
import { NextConfig } from 'next';
type RequiredSelection<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
interface DistZipOptions {
/**
* Output ZIP archive file name.
* You can use `[templateName]` placeholder to replace it with the template name.
* @default `${templateName}.zip`
*/
outFileName?: string;
/**
* Output directory for the build.
* @default 'dist-zip'
*/
outDir?: string;
}
interface VitePPDevOptions {
/**
* Backend base URL to MI instance for the local proxy.
*/
backendBaseURL?: string;
/**
* Portal page ID on the MI instance.
* @deprecated Use appId instead
*/
portalPageId?: number;
/**
* Application ID on the MI instance.
* This is a synonym for portalPageId.
*/
appId?: number;
/**
* Template name or PP internal name that will be used for the asset generation.
* Equals to package.json name field value.
*/
templateName: string;
/**
* Enable or disable template variables loading from the backend.
*/
templateLess?: boolean;
/**
* Enable or disable MI top bar and scripts loading from the backend for local development.
*/
miHudLess?: boolean;
/**
* Enable or disable request caching to the backend by the local proxy.
* @default true
*/
enableProxyCache?: boolean;
/**
* Request caching time in milliseconds.
* @default 600000 (10 minutes)
*/
proxyCacheTTL?: number;
/**
* Disable SSL certificate validation for MI instances with self-signed certificates.
* @default false
*/
disableSSLValidation?: boolean;
/**
* Image optimizer options.
* @default true
*/
imageOptimizer?: boolean | Parameters<typeof ViteImageOptimizer>[0];
/**
* Output directory for the build.
* @default 'dist'
*/
outDir?: string;
/**
* Disable or enable packing the build output into a ZIP archive.
* @default true
*/
distZip?: boolean | DistZipOptions;
/**
* Backups an asset directory path for sync with the MI instance.
* @default backups
*/
syncBackupsDir?: string;
/**
* Enable Metric Insights v7 features.
* @default false
* @since 0.8.0
*/
v7Features?: boolean;
/**
* Personal Access Token for the MI instance.
* @default process.env.MI_ACCESS_TOKEN
* @since 0.10.0
* @example
* ```ts
* import vitePPDev from '@metricinsights/pp-dev';
*
* export default vitePPDev({
* personalAccessToken: process.env.MI_ACCESS_TOKEN,
* // other options...
* });
* ```
*/
personalAccessToken?: string;
}
type NormalizedVitePPDevOptions = RequiredSelection<VitePPDevOptions, 'templateName' | 'templateLess' | 'miHudLess' | 'enableProxyCache' | 'proxyCacheTTL' | 'disableSSLValidation' | 'imageOptimizer' | 'outDir' | 'distZip' | 'syncBackupsDir' | 'v7Features' | 'personalAccessToken'>;
type PPDevConfig = Omit<VitePPDevOptions, 'templateName'>;
type PPWatchConfig = {
baseURL: string;
portalPageId: number;
};
declare module 'vite' {
interface UserConfig {
ppDevConfig?: NormalizedVitePPDevOptions;
}
}
declare function getViteConfig(): Promise<InlineConfig>;
declare function withPPDev(nextjsConfig: NextConfig | ((phase: string, nextConfig?: {
defaultConfig?: any;
}) => NextConfig | Promise<NextConfig>), ppDevConfig?: PPDevConfig): (phase: string, nextConfig?: {
defaultConfig?: any;
}) => Promise<NextConfig>;
export { getViteConfig, withPPDev };
export type { PPDevConfig, PPWatchConfig };