Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: remove cjs build from vite core
  • Loading branch information
sapphi-red committed May 20, 2025
commit 1570a2fd36efe7e14f45b73ce9cf380d7626698e
96 changes: 0 additions & 96 deletions packages/vite/index.cjs

This file was deleted.

6 changes: 0 additions & 6 deletions packages/vite/index.d.cts

This file was deleted.

6 changes: 1 addition & 5 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
"main": "./dist/node/index.js",
"types": "./dist/node/index.d.ts",
"exports": {
".": {
"module-sync": "./dist/node/index.js",
"import": "./dist/node/index.js",
"require": "./index.cjs"
},
".": "./dist/node/index.js",
"./client": {
"types": "./client.d.ts"
},
Expand Down
50 changes: 0 additions & 50 deletions packages/vite/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,32 +169,11 @@ const moduleRunnerConfig = defineConfig({
},
})

const cjsConfig = defineConfig({
...sharedNodeOptions,
input: {
publicUtils: path.resolve(__dirname, 'src/node/publicUtils.ts'),
},
output: {
...sharedNodeOptions.output,
entryFileNames: `node-cjs/[name].cjs`,
chunkFileNames: 'node-cjs/chunks/dep-[hash].js',
format: 'cjs',
target: 'node20',
},
external: ['fsevents', 'supports-color', ...Object.keys(pkg.dependencies)],
plugins: [
bundleSizeLimit(120),
exportCheck(),
externalizeDepsInWatchPlugin(),
],
})

export default defineConfig([
envConfig,
clientConfig,
nodeConfig,
moduleRunnerConfig,
cjsConfig,
])

// #region Plugins
Expand Down Expand Up @@ -430,33 +409,4 @@ function bundleSizeLimit(limit: number): Plugin {
}
}

function exportCheck(): Plugin {
return {
name: 'export-check',
async writeBundle() {
if (this.meta.watchMode) return

// escape import so that it's not bundled while config load
const dynImport = (id: string) => import(id)
// ignore warning from CJS entrypoint to avoid misleading logs
process.env.VITE_CJS_IGNORE_WARNING = 'true'

const esmNamespace = await dynImport('./dist/node/index.js')
const cjsModuleExports = (await dynImport('./index.cjs')).default
const cjsModuleExportsKeys = new Set(
Object.getOwnPropertyNames(cjsModuleExports),
)
const lackingExports = Object.keys(esmNamespace).filter(
(key) => !cjsModuleExportsKeys.has(key),
)
if (lackingExports.length > 0) {
this.error(
`Exports missing from cjs build: ${lackingExports.join(', ')}.` +
` Please update index.cjs or src/publicUtils.ts.`,
)
}
},
}
}

// #endregion
3 changes: 2 additions & 1 deletion packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import type { InlineConfig, PluginOption } from '..'
import type { UserConfig, UserConfigExport } from '../config'
import { defineConfig, loadConfigFromFile, resolveConfig } from '../config'
import { resolveEnvPrefix } from '../env'
import { createLogger, mergeConfig } from '../publicUtils'
import { mergeConfig } from '../utils'
import { createLogger } from '../logger'

describe('mergeConfig', () => {
test('handles configs with different alias schemas', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests_dts__/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type UserConfigFnPromise,
defineConfig,
} from '../config'
import { mergeConfig } from '../publicUtils'
import { mergeConfig } from '../utils'

const configObjectDefined = defineConfig({})
const configObjectPromiseDefined = defineConfig(Promise.resolve({}))
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
emptyDir,
getPkgName,
joinUrlSegments,
mergeConfig,
mergeWithDefaults,
normalizePath,
partialEncodeURIPath,
Expand All @@ -70,7 +71,6 @@ import {
resolveEmptyOutDir,
} from './watch'
import { completeSystemWrapPlugin } from './plugins/completeSystemWrap'
import { mergeConfig } from './publicUtils'
import { webWorkerPostPlugin } from './plugins/worker'
import { getHookHandler } from './plugins'
import {
Expand Down
6 changes: 1 addition & 5 deletions packages/vite/src/node/publicUtils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/**
* Exported sync utils should go here.
* This file will be bundled to ESM and CJS and redirected by ../index.cjs
* Please control the side-effects by checking the ./dist/node-cjs/publicUtils.cjs bundle
*/
// TODO: move contents of this file to src/node/index.ts
export {
VERSION as version,
DEFAULT_CLIENT_CONDITIONS as defaultClientConditions,
Expand Down