diff --git a/src/index.ts b/src/index.ts index d530fc5..75d8965 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,12 +6,13 @@ import path from 'path' import colors from 'picocolors' import { Plugin, loadEnv, UserConfig, ConfigEnv, ResolvedConfig, SSROptions, PluginOption } from 'vite' import fullReload, { Config as FullReloadConfig } from 'vite-plugin-full-reload' +import { InputOption } from "rollup" interface PluginConfig { /** * The path or paths of the entry points to compile. */ - input: string|string[] + input: InputOption /** * Laravel's public directory. @@ -37,7 +38,7 @@ interface PluginConfig { /** * The path of the SSR entry point. */ - ssr?: string|string[] + ssr?: InputOption /** * The directory where the SSR bundle should be written. @@ -368,7 +369,7 @@ function resolveBase(config: Required, assetUrl: string): string { /** * Resolve the Vite input path from the configuration. */ -function resolveInput(config: Required, ssr: boolean): string|string[]|undefined { +function resolveInput(config: Required, ssr: boolean): InputOption|undefined { if (ssr) { return config.ssr } diff --git a/tests/index.test.ts b/tests/index.test.ts index f4bf776..5b602b5 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -81,6 +81,45 @@ describe('laravel-vite-plugin', () => { expect(ssrConfig.build.rollupOptions.input).toBe('resources/js/ssr.ts') }) + it('accepts a single input within a full configuration', () => { + const plugin = laravel({ + input: 'resources/js/app.ts', + ssr: 'resources/js/ssr.ts', + })[0] + + const config = plugin.config({}, { command: 'build', mode: 'production' }) + expect(config.build.rollupOptions.input).toBe('resources/js/app.ts') + + const ssrConfig = plugin.config({ build: { ssr: true } }, { command: 'build', mode: 'production' }) + expect(ssrConfig.build.rollupOptions.input).toBe('resources/js/ssr.ts') + }) + + it('accepts an array of inputs within a full configuration', () => { + const plugin = laravel({ + input: ['resources/js/app.ts', 'resources/js/other.js'], + ssr: ['resources/js/ssr.ts', 'resources/js/other.js'], + })[0] + + const config = plugin.config({}, { command: 'build', mode: 'production' }) + expect(config.build.rollupOptions.input).toEqual(['resources/js/app.ts', 'resources/js/other.js']) + + const ssrConfig = plugin.config({ build: { ssr: true } }, { command: 'build', mode: 'production' }) + expect(ssrConfig.build.rollupOptions.input).toEqual(['resources/js/ssr.ts', 'resources/js/other.js']) + }) + + it('accepts an input object within a full configuration', () => { + const plugin = laravel({ + input: { app: 'resources/js/entrypoint-browser.js' }, + ssr: { ssr: 'resources/js/entrypoint-ssr.js' }, + })[0] + + const config = plugin.config({}, { command: 'build', mode: 'production' }) + expect(config.build.rollupOptions.input).toEqual({ app: 'resources/js/entrypoint-browser.js' }) + + const ssrConfig = plugin.config({ build: { ssr: true } }, { command: 'build', mode: 'production' }) + expect(ssrConfig.build.rollupOptions.input).toEqual({ ssr: 'resources/js/entrypoint-ssr.js' }) + }) + it('respects the users build.manifest config option', () => { const plugin = laravel({ input: 'resources/js/app.js',