Skip to content
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,13 @@ You can define custom `render`/`createContext` calls by using the `imports` opti
],
}
```

## Other Configs

### Granular Mode

Granular mode for HMR (which allows independent HMR for components and templates) is enabled by default. You can disable this by adding `granular: false`.

### JSX HMR

JSX, by default, is moved to a separate component to perform granular HMR. To disable this, add `jsx: false`.
2 changes: 2 additions & 0 deletions src/babel/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type ImportDefinition = DefaultImportDefinition | NamedImportDefinition;

export interface Options {
granular?: boolean;
jsx?: boolean;
bundler?: RuntimeType;
fixRender?: boolean;
imports?: {
Expand All @@ -32,6 +33,7 @@ export interface ImportIdentifierSpecifier {
}

export interface StateContext {
jsx: boolean;
granular: boolean;
opts: Options;
specifiers: ImportIdentifierSpecifier[];
Expand Down
19 changes: 11 additions & 8 deletions src/babel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export default function solidRefreshPlugin(): babel.PluginObj<State> {
visitor: {
Program(programPath, context) {
const state: StateContext = {
jsx: context.opts.jsx ?? true,
granular: context.opts.granular ?? true,
opts: context.opts,
specifiers: [...IMPORT_SPECIFIERS],
Expand All @@ -356,14 +357,16 @@ export default function solidRefreshPlugin(): babel.PluginObj<State> {
bubbleFunctionDeclaration(programPath, path);
},
});
programPath.traverse({
JSXElement(path) {
transformJSX(path);
},
JSXFragment(path) {
transformJSX(path);
},
});
if (state.jsx) {
programPath.traverse({
JSXElement(path) {
transformJSX(path);
},
JSXFragment(path) {
transformJSX(path);
},
});
}
programPath.traverse({
VariableDeclarator(path) {
transformVariableDeclarator(state, path);
Expand Down