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 plugin-legacy
  • Loading branch information
sapphi-red committed May 20, 2025
commit 378e211e862400702d5db6d2e03cbd59928af6a6
13 changes: 2 additions & 11 deletions packages/plugin-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,10 @@
"vite-plugin",
"@vitejs/plugin-legacy"
],
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"exports": "./dist/index.js",
"scripts": {
"dev": "tsdown --watch",
"build": "tsdown && pnpm run patch-cjs",
"patch-cjs": "tsx ../../scripts/patchCJS.ts",
"build": "tsdown",
"prepublishOnly": "npm run build"
},
"engines": {
Expand Down
12 changes: 12 additions & 0 deletions packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,3 +997,15 @@ export const cspHashes = [
export type { Options }

export default viteLegacyPlugin

// Compat for require
function viteLegacyPluginCjs(this: unknown, options: Options): Plugin[] {
return viteLegacyPlugin.call(this, options)
}
Object.assign(viteLegacyPluginCjs, {
cspHashes,
default: viteLegacyPluginCjs,
detectPolyfills,
})

export { viteLegacyPluginCjs as 'module.exports' }
7 changes: 0 additions & 7 deletions packages/plugin-legacy/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ import { defineConfig } from 'tsdown'

export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
target: 'node20',
tsconfig: false, // disable tsconfig `paths` when bundling
outputOptions(opts, format) {
if (format === 'cjs') {
opts.exports = 'named'
}
return opts
},
})