Skip to content

Commit f3d3570

Browse files
authored
Add jsx option (#61)
1 parent 69d8070 commit f3d3570

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,13 @@ You can define custom `render`/`createContext` calls by using the `imports` opti
216216
],
217217
}
218218
```
219+
220+
## Other Configs
221+
222+
### Granular Mode
223+
224+
Granular mode for HMR (which allows independent HMR for components and templates) is enabled by default. You can disable this by adding `granular: false`.
225+
226+
### JSX HMR
227+
228+
JSX, by default, is moved to a separate component to perform granular HMR. To disable this, add `jsx: false`.

src/babel/core/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type ImportDefinition = DefaultImportDefinition | NamedImportDefinition;
1616

1717
export interface Options {
1818
granular?: boolean;
19+
jsx?: boolean;
1920
bundler?: RuntimeType;
2021
fixRender?: boolean;
2122
imports?: {
@@ -32,6 +33,7 @@ export interface ImportIdentifierSpecifier {
3233
}
3334

3435
export interface StateContext {
36+
jsx: boolean;
3537
granular: boolean;
3638
opts: Options;
3739
specifiers: ImportIdentifierSpecifier[];

src/babel/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ export default function solidRefreshPlugin(): babel.PluginObj<State> {
336336
visitor: {
337337
Program(programPath, context) {
338338
const state: StateContext = {
339+
jsx: context.opts.jsx ?? true,
339340
granular: context.opts.granular ?? true,
340341
opts: context.opts,
341342
specifiers: [...IMPORT_SPECIFIERS],
@@ -356,14 +357,16 @@ export default function solidRefreshPlugin(): babel.PluginObj<State> {
356357
bubbleFunctionDeclaration(programPath, path);
357358
},
358359
});
359-
programPath.traverse({
360-
JSXElement(path) {
361-
transformJSX(path);
362-
},
363-
JSXFragment(path) {
364-
transformJSX(path);
365-
},
366-
});
360+
if (state.jsx) {
361+
programPath.traverse({
362+
JSXElement(path) {
363+
transformJSX(path);
364+
},
365+
JSXFragment(path) {
366+
transformJSX(path);
367+
},
368+
});
369+
}
367370
programPath.traverse({
368371
VariableDeclarator(path) {
369372
transformVariableDeclarator(state, path);

0 commit comments

Comments
 (0)