Skip to content

Commit 83e95a5

Browse files
authored
Use Rollup InputOption for entrypoint types (#298)
1 parent a5ed2c2 commit 83e95a5

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import path from 'path'
66
import colors from 'picocolors'
77
import { Plugin, loadEnv, UserConfig, ConfigEnv, ResolvedConfig, SSROptions, PluginOption } from 'vite'
88
import fullReload, { Config as FullReloadConfig } from 'vite-plugin-full-reload'
9+
import { InputOption } from "rollup"
910

1011
interface PluginConfig {
1112
/**
1213
* The path or paths of the entry points to compile.
1314
*/
14-
input: string|string[]
15+
input: InputOption
1516

1617
/**
1718
* Laravel's public directory.
@@ -37,7 +38,7 @@ interface PluginConfig {
3738
/**
3839
* The path of the SSR entry point.
3940
*/
40-
ssr?: string|string[]
41+
ssr?: InputOption
4142

4243
/**
4344
* The directory where the SSR bundle should be written.
@@ -368,7 +369,7 @@ function resolveBase(config: Required<PluginConfig>, assetUrl: string): string {
368369
/**
369370
* Resolve the Vite input path from the configuration.
370371
*/
371-
function resolveInput(config: Required<PluginConfig>, ssr: boolean): string|string[]|undefined {
372+
function resolveInput(config: Required<PluginConfig>, ssr: boolean): InputOption|undefined {
372373
if (ssr) {
373374
return config.ssr
374375
}

tests/index.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,45 @@ describe('laravel-vite-plugin', () => {
8181
expect(ssrConfig.build.rollupOptions.input).toBe('resources/js/ssr.ts')
8282
})
8383

84+
it('accepts a single input within a full configuration', () => {
85+
const plugin = laravel({
86+
input: 'resources/js/app.ts',
87+
ssr: 'resources/js/ssr.ts',
88+
})[0]
89+
90+
const config = plugin.config({}, { command: 'build', mode: 'production' })
91+
expect(config.build.rollupOptions.input).toBe('resources/js/app.ts')
92+
93+
const ssrConfig = plugin.config({ build: { ssr: true } }, { command: 'build', mode: 'production' })
94+
expect(ssrConfig.build.rollupOptions.input).toBe('resources/js/ssr.ts')
95+
})
96+
97+
it('accepts an array of inputs within a full configuration', () => {
98+
const plugin = laravel({
99+
input: ['resources/js/app.ts', 'resources/js/other.js'],
100+
ssr: ['resources/js/ssr.ts', 'resources/js/other.js'],
101+
})[0]
102+
103+
const config = plugin.config({}, { command: 'build', mode: 'production' })
104+
expect(config.build.rollupOptions.input).toEqual(['resources/js/app.ts', 'resources/js/other.js'])
105+
106+
const ssrConfig = plugin.config({ build: { ssr: true } }, { command: 'build', mode: 'production' })
107+
expect(ssrConfig.build.rollupOptions.input).toEqual(['resources/js/ssr.ts', 'resources/js/other.js'])
108+
})
109+
110+
it('accepts an input object within a full configuration', () => {
111+
const plugin = laravel({
112+
input: { app: 'resources/js/entrypoint-browser.js' },
113+
ssr: { ssr: 'resources/js/entrypoint-ssr.js' },
114+
})[0]
115+
116+
const config = plugin.config({}, { command: 'build', mode: 'production' })
117+
expect(config.build.rollupOptions.input).toEqual({ app: 'resources/js/entrypoint-browser.js' })
118+
119+
const ssrConfig = plugin.config({ build: { ssr: true } }, { command: 'build', mode: 'production' })
120+
expect(ssrConfig.build.rollupOptions.input).toEqual({ ssr: 'resources/js/entrypoint-ssr.js' })
121+
})
122+
84123
it('respects the users build.manifest config option', () => {
85124
const plugin = laravel({
86125
input: 'resources/js/app.js',

0 commit comments

Comments
 (0)