From fb0a43780a7462f4876955c3412638e51a7adb97 Mon Sep 17 00:00:00 2001 From: Ryan Christian <33403762+rschristian@users.noreply.github.com> Date: Thu, 3 Mar 2022 11:09:14 -0600 Subject: [PATCH] chore: Adding flag & docs for jsxFragment (#930) --- .changeset/odd-mayflies-clap.md | 5 +++++ README.md | 1 + src/index.js | 12 ++++-------- src/prog.js | 5 +++++ 4 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 .changeset/odd-mayflies-clap.md diff --git a/.changeset/odd-mayflies-clap.md b/.changeset/odd-mayflies-clap.md new file mode 100644 index 00000000..75984f15 --- /dev/null +++ b/.changeset/odd-mayflies-clap.md @@ -0,0 +1,5 @@ +--- +'microbundle': patch +--- + +Documenting --jsxFragment flag diff --git a/README.md b/README.md index f86d3fee..26e074d8 100644 --- a/README.md +++ b/README.md @@ -335,6 +335,7 @@ Options --sourcemap Generate source map (default true) --raw Show raw byte size (default false) --jsx A custom JSX pragma like React.createElement (default: h) + --jsxFragment A custom JSX fragment pragma like React.Fragment (default: Fragment) --jsxImportSource Declares the module specifier to be used for importing jsx factory functions --tsconfig Specify the path to a custom tsconfig.json --generateTypes Whether or not to generate types, if `types` or `typings` is set in `package.json` then it will default to be `true` diff --git a/src/index.js b/src/index.js index f47a6dda..d5a77954 100644 --- a/src/index.js +++ b/src/index.js @@ -536,12 +536,8 @@ function createConfig(options, entry, format, writeMeta) { declarationDir: getDeclarationDir({ options, pkg }), }), jsx: 'preserve', - jsxFactory: - // TypeScript fails to resolve Fragments when jsxFactory - // is set, even when it's the same as the default value. - options.jsx === 'React.createElement' - ? undefined - : options.jsx || 'h', + jsxFactory: options.jsx, + jsxFragmentFactory: options.jsxFragment, }, files: options.entries, }, @@ -578,8 +574,8 @@ function createConfig(options, entry, format, writeMeta) { modern, compress: options.compress !== false, targets: options.target === 'node' ? { node: '8' } : undefined, - pragma: options.jsx || 'h', - pragmaFrag: options.jsxFragment || 'Fragment', + pragma: options.jsx, + pragmaFrag: options.jsxFragment, typescript: !!useTypescript, jsxImportSource: options.jsxImportSource || false, }, diff --git a/src/prog.js b/src/prog.js index 4f48a573..6049501c 100644 --- a/src/prog.js +++ b/src/prog.js @@ -59,6 +59,11 @@ export default handler => { .example("watch --no-sourcemap # don't generate sourcemaps") .option('--raw', 'Show raw byte size', false) .option('--jsx', 'A custom JSX pragma like React.createElement', 'h') + .option( + '--jsxFragment', + 'A custom JSX fragment pragma like React.Fragment', + 'Fragment', + ) .option( '--jsxImportSource', 'Declares the module specifier to be used for importing jsx factory functions',