Skip to content

Commit

Permalink
Use Rollup InputOption for entrypoint types (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlwsmith authored Jul 8, 2024
1 parent a5ed2c2 commit 83e95a5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -368,7 +369,7 @@ function resolveBase(config: Required<PluginConfig>, assetUrl: string): string {
/**
* Resolve the Vite input path from the configuration.
*/
function resolveInput(config: Required<PluginConfig>, ssr: boolean): string|string[]|undefined {
function resolveInput(config: Required<PluginConfig>, ssr: boolean): InputOption|undefined {
if (ssr) {
return config.ssr
}
Expand Down
39 changes: 39 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 83e95a5

Please sign in to comment.