vite#mergeConfig TypeScript Examples

The following examples show how to use vite#mergeConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From reskript with MIT License 6 votes vote down vote up
createViteConfig = async (context: BuildContext, input: ViteOptions): Promise<UserConfig> => {
    if (context.entries.length !== 1) {
        logger.error('Currently vite driver only supports one application entry.');
        process.exit(24);
    }

    // 兼容一下`publicPath`有没有最后的`/`的情况
    const options = {...input, publicPath: input.publicPath + (input.publicPath.endsWith('/') ? '' : '/')};
    const parts = await Promise.all(factories.map(v => v(context, options)));
    const config = parts.reduce((output, current) => mergeConfig(output, current)) as FinalizableViteConfiguration;
    const serverFinalized = {
        ...config,
        server: await context.projectSettings.devServer.finalize(config.server, context),
    };
    warnAndExitOnInvalidFinalizeReturn(serverFinalized, 'devServer');

    const finalized = await context.projectSettings.build.finalize(serverFinalized, context);
    warnAndExitOnInvalidFinalizeReturn(finalized, 'build');

    return finalized;
}