diff --git a/packages/cli/src/build/build.ts b/packages/cli/src/build/build.ts index 9e229e0600..30f2f5171e 100644 --- a/packages/cli/src/build/build.ts +++ b/packages/cli/src/build/build.ts @@ -38,6 +38,7 @@ const DEFAULT_CONFIG: Partial = { dest: 'output', files: 'src/*', overridesDir: 'overrides', + extension: 'lite.tsx', }; const getOptions = (config?: MitosisConfig): MitosisConfig => ({ @@ -93,7 +94,7 @@ const getRequiredParsers = ( const getMitosisComponentJSONs = async (options: MitosisConfig): Promise => { const requiredParses = getRequiredParsers(options); return Promise.all( - micromatch(await glob(options.files, { cwd }), `**/*.${options.extension ?? 'lite.tsx'}`).map( + micromatch(await glob(options.files, { cwd }), `**/*.${options.extension}`).map( async (path): Promise => { try { const file = await readFile(path, 'utf8'); @@ -250,8 +251,10 @@ const replaceFileExtensionForTarget = ({ target: Target; path: string; options: MitosisConfig; -}) => - path.replace(/\.lite\.tsx$/, getFileExtensionForTarget({ type: 'filename', target, options })); +}) => { + let regex = new RegExp(`.${options.extension}$`); + return path.replace(regex, getFileExtensionForTarget({ type: 'filename', target, options })); +}; /** * Transpiles and outputs Mitosis component files. diff --git a/packages/cli/src/build/helpers/transpile.ts b/packages/cli/src/build/helpers/transpile.ts index 5690f2d0a2..704722ace9 100644 --- a/packages/cli/src/build/helpers/transpile.ts +++ b/packages/cli/src/build/helpers/transpile.ts @@ -20,6 +20,10 @@ export const transformImports = (target: Target, options: MitosisConfig) => (cod // afterwards, we replace all `.lite` imports with the correct file extension /\.lite(['"][;\)])/g, `${getFileExtensionForTarget({ type: 'import', target, options })}$1`, + ) + .replace( + `.${options.extension}`, + `${getFileExtensionForTarget({ type: 'import', target, options })}`, ); /** diff --git a/packages/core/src/types/config.ts b/packages/core/src/types/config.ts index af8ade5b12..72507f566d 100644 --- a/packages/core/src/types/config.ts +++ b/packages/core/src/types/config.ts @@ -57,7 +57,7 @@ export type MitosisConfig = { * Configure the extension of the files you want to compile * Default value: 'lite.tsx' */ - extension?: string; + extension: string; /** * Configure a custom parser function which takes a string and returns MitosisJSON * Defaults to the JSXParser of this project (src/parsers/jsx)