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

Draft: Vite refactorings #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/vite/src/backend/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Arr } from '@supercharge/arrays'
import { ViteConfig } from './vite-config.js'
import { ViteManifest } from './vite-manifest.js'
import { HtmlString } from '@supercharge/support'
import { HotReloadFileContent } from '../plugin/types.js'
import { HotReloadFileContent } from '../plugin/vite-plugin-types.js'

export type ViteTagAttributes = Record<string, any>

Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { supercharge } from './plugin/plugin.js'
import { supercharge } from './plugin/vite-plugin.js'

export default supercharge
export { supercharge }
Expand All @@ -11,5 +11,5 @@ export { ViteServiceProvider } from './vite-service-provider.js'
export { resolvePageComponent } from './inertia/inertia-helpers.js'
export { InertiaPageNotFoundError } from './inertia/inertia-page-not-found-error.js'

export { HotReloadFile } from './plugin/hotfile.js'
export { PluginConfigContract, DevServerUrl } from './plugin/types.js'
export { HotReloadFile } from './plugin/vite-hotfile.js'
export { PluginConfigContract, DevServerUrl } from './plugin/vite-plugin-types.js'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import Fs from 'node:fs'
import Path from 'node:path'
import { HotReloadFileContent } from './types.js'
import { HotReloadFileContent } from './vite-plugin-types.js'

export class HotReloadFile {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ export type DevServerUrl = `${'http' | 'https'}://${string}:${number}`
export interface PluginConfigContract {
/**
* The path or paths to the entrypoints to compile with Vite.
*
* @deprecated use the {@link entrypoints} property
*/
input: string | string[]

/**
* The path or paths to the entrypoints to compile with Vite.
*/
entrypoints: string | string[]

/**
* The "public" directory name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import Path from 'node:path'
import { AddressInfo } from 'node:net'
import { Str } from '@supercharge/strings'
import { HotReloadFile } from './hotfile.js'
import { DevServerUrl, PluginConfigContract } from './types.js'
import { HotReloadFile } from './vite-hotfile.js'
import { DevServerUrl, PluginConfigContract } from './vite-plugin-types.js'
import { ConfigEnv, Plugin, ResolvedConfig, UserConfig, ViteDevServer } from 'vite'

/**
Expand All @@ -20,19 +20,23 @@ export function supercharge (config: string | string[] | PluginConfigContract):
*/
function resolvePluginConfig (config: string | string[] | PluginConfigContract): Required<PluginConfigContract> {
if (!config) {
throw new Error('supercharge-vite-plugin: missing inputs or configuration')
throw new Error('supercharge-vite-plugin: missing configuration object')
}

if (typeof config === 'string') {
config = [config]
}

if (Array.isArray(config)) {
config = { input: config }
config = { entrypoints: config }
}

if (!config.input) {
throw new Error('supercharge-vite-plugin: missing "input" configuration')
if (!config.entrypoints && config.input) {
config.entrypoints = config.input
}

if (!config.entrypoints) {
throw new Error('supercharge-vite-plugin: missing "entrypoints" configuration')
}

if (typeof config.publicDirectory === 'string') {
Expand Down
Loading