Skip to content

Commit 84e37e4

Browse files
Add ESM support for importing the Vite plugin
1 parent 99e7d5d commit 84e37e4

7 files changed

Lines changed: 38 additions & 12 deletions

File tree

.changeset/large-gifts-sip.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compiled/vite-plugin': patch
3+
---
4+
5+
Split CJS and ESM exports for the Vite Plugin

packages/tsconfig.esm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"files": [],
3-
"references": [{ "path": "react/tsconfig.json" }]
3+
"references": [{ "path": "react/tsconfig.json" }, { "path": "vite-plugin/tsconfig.json" }]
44
}

packages/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{ "path": "parcel-transformer-external/tsconfig.json" },
1414
{ "path": "react/tsconfig.cjs.json" },
1515
{ "path": "utils/tsconfig.json" },
16-
{ "path": "vite-plugin/tsconfig.json" },
16+
{ "path": "vite-plugin/tsconfig.cjs.json" },
1717
{ "path": "webpack-loader/tsconfig.json" }
1818
]
1919
}

packages/vite-plugin/package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
"sideEffects": false,
1515
"exports": {
1616
".": {
17-
"types": "./dist/index.d.ts",
18-
"import": "./dist/index.js",
19-
"require": "./dist/index.js",
20-
"default": "./dist/index.js"
17+
"types": "./dist/esm/index.d.ts",
18+
"import": "./dist/esm/index.js",
19+
"require": "./dist/cjs/index.js"
2120
}
2221
},
23-
"main": "./dist/index.js",
24-
"module": "./dist/index.js",
25-
"types": "./dist/index.d.ts",
22+
"main": "./dist/cjs/index.js",
23+
"module": "./dist/esm/index.js",
24+
"types": "./dist/esm/index.d.ts",
2625
"files": [
2726
"dist",
2827
"src"

packages/vite-plugin/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { createDefaultResolver } from './utils';
1919
* @param userOptions - Plugin configuration options
2020
* @returns Vite plugin object
2121
*/
22-
export default function compiledVitePlugin(userOptions: PluginOptions = {}): any {
22+
function compiled(userOptions: PluginOptions = {}): any {
2323
const options: PluginOptions = {
2424
// Vite-specific
2525
bake: true,
@@ -273,4 +273,6 @@ export default function compiledVitePlugin(userOptions: PluginOptions = {}): any
273273
};
274274
}
275275

276+
export { compiled };
276277
export type { PluginOptions as VitePluginOptions };
278+
export default compiled;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "../tsconfig.options.json",
3+
"compilerOptions": {
4+
"rootDir": "./src",
5+
"outDir": "./dist/cjs",
6+
"skipLibCheck": true,
7+
"tsBuildInfoFile": "tsconfig.cjs.tsbuildinfo"
8+
},
9+
"include": ["./src/**/*"],
10+
"exclude": ["./src/__tests__/**/*"],
11+
"references": [
12+
{ "path": "../babel-plugin/tsconfig.json" },
13+
{ "path": "../babel-plugin-strip-runtime/tsconfig.json" },
14+
{ "path": "../css/tsconfig.json" },
15+
{ "path": "../utils/tsconfig.json" }
16+
]
17+
}

packages/vite-plugin/tsconfig.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
"extends": "../tsconfig.options.json",
33
"compilerOptions": {
44
"rootDir": "./src",
5-
"outDir": "./dist",
6-
"skipLibCheck": true
5+
"outDir": "./dist/esm",
6+
"module": "es6",
7+
"moduleResolution": "node",
8+
"skipLibCheck": true,
9+
"tsBuildInfoFile": "tsconfig.esm.tsbuildinfo"
710
},
811
"include": ["./src/**/*"],
912
"exclude": ["./src/__tests__/**/*"],

0 commit comments

Comments
 (0)