Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript: define entrypoints using object #298

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading