Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow jsxFactory and jsxFragment to be passed in buildOptions for use by esbuild #1838

Merged
merged 2 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions snowpack/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ const configSchema = {
watch: {type: 'boolean'},
ssr: {type: 'boolean'},
htmlFragments: {type: 'boolean'},
jsxFactory: {type: 'string'},
jsxFragment: {type: 'string'},
},
},
testOptions: {
Expand Down
6 changes: 4 additions & 2 deletions snowpack/src/plugins/plugin-esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export function esbuildPlugin(config: SnowpackConfig, {input}: {input: string[]}
esbuildService = esbuildService || (await startService());
const contents = await fs.readFile(filePath, 'utf-8');
const isPreact = checkIsPreact(filePath, contents);
let jsxFactory = config.buildOptions.jsxFactory ?? (isPreact ? 'h' : undefined);
let jsxFragment = config.buildOptions.jsxFragment ?? (isPreact ? 'Fragment' : undefined);
const {code, map, warnings} = await esbuildService!.transform(contents, {
loader: getLoader(filePath),
jsxFactory: isPreact ? 'h' : undefined,
jsxFragment: isPreact ? 'Fragment' : undefined,
jsxFactory,
jsxFragment,
sourcefile: filePath,
sourcemap: config.buildOptions.sourceMaps,
});
Expand Down
2 changes: 2 additions & 0 deletions snowpack/src/types/snowpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ export interface SnowpackConfig {
sourceMaps: boolean;
watch: boolean;
htmlFragments: boolean;
jsxFactory: string | undefined;
jsxFragment: string | undefined;
};
testOptions: {
files: string[];
Expand Down
8 changes: 8 additions & 0 deletions www/_template/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ module.exports = {

- Rename your web modules directory.

#### buildOptions.jsxFactory | `string` | Default: `React.createElement` (or `h` if Preact import is detected)

- Set the name of the used function to create JSX elements.

#### buildOptions.jsxFragment | `string` | Default: `React.Fragment` (or `Fragment` if Preact import is detected)

- Set the name of the used function to create JSX fragments.

### config.testOptions

#### testOptions.files | `string[]` | Default: `["__tests__/**/*", "**/*.@(spec|test).*"]`
Expand Down