Skip to content
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
16 changes: 15 additions & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ import {
import type { LogLevel, Logger } from './logger'
import { createLogger } from './logger'
import type { DepOptimizationOptions } from './optimizer'
import type { JsonOptions } from './plugins/json'
import type { PackageCache } from './packages'
import { findNearestNodeModules, findNearestPackageData } from './packages'
import { loadEnv, resolveEnvPrefix } from './env'
Expand Down Expand Up @@ -326,6 +325,21 @@ export type ResolvedEnvironmentOptions = {
optimizeDepsPluginNames: string[]
}

export interface JsonOptions {
/**
* Generate a named export for every property of the JSON object
* @default true
*/
namedExports?: boolean
/**
* Generate performant output as JSON.parse("stringified").
*
* When set to 'auto', the data will be stringified only if the data is bigger than 10kB.
* @default 'auto'
*/
stringify?: boolean | 'auto'
}

export type DefaultEnvironmentOptions = Omit<
EnvironmentOptions,
'consumer' | 'resolve' | 'keepProcessEnv'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export type {
PluginHookUtils,
ResolveFn,
ResolvedWorkerOptions,
JsonOptions,
ResolvedConfig,
UserConfig,
UserConfigExport,
Expand Down Expand Up @@ -200,7 +201,6 @@ export type {
LessPreprocessorOptions,
StylusPreprocessorOptions,
} from './plugins/css'
export type { JsonOptions } from './plugins/json'
export type { ESBuildOptions } from './plugins/esbuild'
export type { EsbuildTransformOptions } from '#types/internal/esbuildOptions'
export type { OxcOptions } from './plugins/oxc'
Expand Down
19 changes: 0 additions & 19 deletions packages/vite/src/node/plugins/json.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {
combineSourcemaps,
generateCodeFrame,
isDefined,
isJSONRequest,
numberToPos,
} from '../utils'
import { isJSONRequest } from '../plugins/json'
import type { DefineImportMetadata } from '../../shared/ssrTransform'

type Node = _Node & {
Expand Down
5 changes: 5 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1763,3 +1763,8 @@ export function monotonicDateNow(): number {
lastDateNow++
return lastDateNow
}

const jsonLangs = `\\.(?:json|json5)(?:$|\\?)`
const jsonLangRE = new RegExp(jsonLangs)
export const isJSONRequest = (request: string): boolean =>
jsonLangRE.test(request)