From be48701a7847a509259f23812138ef62b9026567 Mon Sep 17 00:00:00 2001 From: Nicolas Merget <104347736+nmerget@users.noreply.github.com> Date: Wed, 13 Nov 2024 19:22:34 +0100 Subject: [PATCH] docs: update configuration docs to reflect current MitosisConfig type (#1633) * docs: update configuration docs to reflect current MitosisConfig type * chore: removed changeset --- packages/core/src/types/config.ts | 4 ++ .../src/routes/docs/configuration/index.mdx | 70 +++++++++++++++---- 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/packages/core/src/types/config.ts b/packages/core/src/types/config.ts index 4aef8adbce..e71d034b1b 100644 --- a/packages/core/src/types/config.ts +++ b/packages/core/src/types/config.ts @@ -21,6 +21,9 @@ export type generatorsOption = { export type MitosisConfig = { generators?: generatorsOption; + /** + * Apply common options to all targets + */ commonOptions?: Omit; /** * List of targets to compile to. @@ -60,6 +63,7 @@ export type MitosisConfig = { * react: { * stateType: 'builder'; * stylesType: 'styled-jsx' + * plugins: [myPlugin] * } * } * ``` diff --git a/packages/docs/src/routes/docs/configuration/index.mdx b/packages/docs/src/routes/docs/configuration/index.mdx index e7532f4977..e6fcb541d4 100644 --- a/packages/docs/src/routes/docs/configuration/index.mdx +++ b/packages/docs/src/routes/docs/configuration/index.mdx @@ -8,10 +8,14 @@ title: Configuration - Mitosis In the root of the project, from which you run mitosis, you can add a `mitosis.config.js` file that will be read by Mitosis. You can also specify a config file by option: `--config=`. -The `mitosis.config.js` file can take the following shape: +The `mitosis.config.js` file uses the [MitosisConfig](https://github.com/BuilderIO/mitosis/blob/main/packages/core/src/types/config.ts#L22) type: ```tsx -type MitosisConfig = { +export type MitosisConfig = { + /** + * Apply common options to all targets + */ + commonOptions?: Omit; /** * List of targets to compile to. */ @@ -50,25 +54,40 @@ type MitosisConfig = { * react: { * stateType: 'builder'; * stylesType: 'styled-jsx' + * plugins: [myPlugin] * } * } * ``` - */ - options: Partial; - /** +*/ +options: Partial; +/** * Configure a custom parser function which takes a string and returns MitosisJSON * Defaults to the JSXParser of this project (src/parsers/jsx) - */ - parser?: (code: string, path?: string) => MitosisComponent | Promise; +*/ +parser?: (code: string, path?: string) => MitosisComponent | Promise; - /** +/** * Configure a custom function that provides the output path for each target. * If you provide this function, you must provide a value for every target yourself. - */ - getTargetPath: ({ target }: { target: Target }) => string; -} +*/ +getTargetPath: ({ target }: { target: Target }) => string; + +/** + * Provide options to the parser. +*/ +parserOptions?: { + jsx: Partial & { + /** + * Path to your project's `tsconfig.json` file. Needed for advanced types parsing (e.g. signals). + */ + tsConfigFilePath?: string; + }; + }; +}; ``` +### Targets + The `Targets` type can be any one of, or an array of the following strings: ```tsx @@ -96,7 +115,34 @@ type targets = | 'taro'; ``` -Note that you can configure each target generator individually, providing plugins on a case-by-case basis. +> **Note** that you can configure each target generator individually, providing [plugins](/docs/customizability/#plugins) on a case-by-case basis. + +### Common options + +The type `BaseTranspilerOptions` for `commonOptions` can be an object like this: + +````ts + +export interface BaseTranspilerOptions { + /** + * Runs `prettier` on generated components + */ + prettier?: boolean; + /** + * Mitosis Plugins to run during codegen. + */ + plugins?: Plugin[]; + /** + * Enable `typescript` output + */ + typescript?: boolean; + /** + * Preserves explicit filename extensions in import statements. + */ + explicitImportFileExtension?: boolean; +} +```` + ### TypeScript configuration