diff --git a/README.md b/README.md index 19bb4c4..57c8ccc 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ npm i -D vite-plugin-sass-dts | typeName.replacement | string \| (fileName: string) => string | Type name can be changed to any value. (default is the classname key as a string. e.g. `theClassName: 'theClassName';`) | | outputDir | string | An absolute path to the output directory. If undefined, declaration files will be generated in the source directories. `) | | sourceDir | string | An absolute path to your source code directory. The plugin will replace this path with `outputDir` option when writing declaration files. `) | +| esmExport | boolean | Specify dts export type. If enabled, going to use ESM style export `export default ...`. Otherwise `export = ...`. | prettierFilePath | string | Specify the path to the prettier configuration file. | ## Add it to vite.config.ts diff --git a/src/type.ts b/src/type.ts index 30d129a..bf4b0dc 100644 --- a/src/type.ts +++ b/src/type.ts @@ -11,6 +11,7 @@ export type PluginOptions = { enabledMode?: ('development' | 'production')[] global?: { generate: boolean; outputFilePath: string } typeName?: { replacement: string | ((fileName: string) => string) } + esmExport?: boolean outputDir?: string sourceDir?: string prettierFilePath?: string diff --git a/src/write.ts b/src/write.ts index 9f67210..24f4e65 100644 --- a/src/write.ts +++ b/src/write.ts @@ -17,7 +17,9 @@ export const writeToFile = async ( ) => { const typeName = getTypeName(path.basename(fileName), options) let exportTypes = '' - const exportStyle = 'export = classNames;' + const exportStyle = options?.esmExport + ? 'export default classNames;' + : 'export = classNames;' for (const classNameKey of classNameKeys.keys()) { exportTypes = `${exportTypes}\n${formatExportType(classNameKey, typeName)}` }