Skip to content

Commit 3f8efbc

Browse files
committed
wip: remove cjs build from plugin-legacy
1 parent 7b8b02f commit 3f8efbc

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

packages/plugin-legacy/build.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export default defineBuildConfig({
55
clean: true,
66
declaration: true,
77
rollup: {
8-
emitCJS: true,
98
inlineDependencies: true,
109
esbuild: {
1110
target: 'node20',

packages/plugin-legacy/package.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,10 @@
1313
"vite-plugin",
1414
"@vitejs/plugin-legacy"
1515
],
16-
"main": "./dist/index.cjs",
17-
"module": "./dist/index.mjs",
18-
"types": "./dist/index.d.ts",
19-
"exports": {
20-
".": {
21-
"import": "./dist/index.mjs",
22-
"require": "./dist/index.cjs"
23-
}
24-
},
16+
"exports": "./dist/index.mjs",
2517
"scripts": {
2618
"dev": "unbuild --stub",
27-
"build": "unbuild && pnpm run patch-cjs",
28-
"patch-cjs": "tsx ../../scripts/patchCJS.ts",
19+
"build": "unbuild",
2920
"prepublishOnly": "npm run build"
3021
},
3122
"engines": {

packages/plugin-legacy/src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,3 +997,16 @@ export const cspHashes = [
997997
export type { Options }
998998

999999
export default viteLegacyPlugin
1000+
1001+
// Compat for require
1002+
function viteLegacyPluginCjs(this: unknown, options: Options): Plugin[] {
1003+
return viteLegacyPlugin.call(this, options)
1004+
}
1005+
Object.assign(viteLegacyPluginCjs, {
1006+
cspHashes,
1007+
default: viteLegacyPluginCjs,
1008+
detectPolyfills,
1009+
})
1010+
1011+
// TODO: https://github.com/unjs/unbuild/issues/533
1012+
export { viteLegacyPluginCjs as 'module.exports' }

0 commit comments

Comments
 (0)