Skip to content

Commit 4990bab

Browse files
authored
Merge pull request #142 from solidjs/refresh-api
Add new `refresh` config
2 parents 9b59fdc + c7d6323 commit 4990bab

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@types/babel__core": "^7.20.4",
4646
"babel-preset-solid": "^1.8.4",
4747
"merge-anything": "^5.1.7",
48-
"solid-refresh": "^0.6.3",
48+
"solid-refresh": "^0.7.2",
4949
"vitefu": "^0.2.5"
5050
},
5151
"devDependencies": {

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { readFileSync } from 'fs';
44
import { mergeAndConcat } from 'merge-anything';
55
import { createRequire } from 'module';
66
import solidRefresh from 'solid-refresh/babel';
7+
// TODO use proper path
8+
import type { Options as RefreshOptions } from 'solid-refresh/babel';
9+
import type { Alias, AliasOptions, FilterPattern, Plugin } from 'vite';
710
import { createFilter } from 'vite';
8-
import type { Alias, AliasOptions, Plugin, FilterPattern } from 'vite';
911
import { crawlFrameworkPkgs } from 'vitefu';
1012

1113
const require = createRequire(import.meta.url);
@@ -51,6 +53,7 @@ export interface Options {
5153
* This will inject HMR runtime in dev mode. Has no effect in prod. If
5254
* set to `false`, it won't inject the runtime in dev.
5355
*
56+
* @deprecated use `refresh` instead
5457
* @default true
5558
*/
5659
hot: boolean;
@@ -142,6 +145,8 @@ export interface Options {
142145
*/
143146
builtIns?: string[];
144147
};
148+
149+
refresh: Omit<RefreshOptions & { disabled: boolean }, 'bundler' | 'fixRender'>;
145150
}
146151

147152
function getExtension(filename: string): string {
@@ -255,7 +260,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
255260
},
256261

257262
configResolved(config) {
258-
needHmr = config.command === 'serve' && config.mode !== 'production' && options.hot !== false;
263+
needHmr = config.command === 'serve' && config.mode !== 'production' && (options.hot !== false && !options.refresh?.disabled);
259264
},
260265

261266
resolveId(id) {
@@ -307,7 +312,19 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
307312

308313
return extensionOptions.typescript;
309314
});
310-
const plugins: NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['plugins']> = ['jsx']
315+
const plugins: NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['plugins']> = [
316+
'jsx',
317+
// import { example } from 'example' with { example: true };
318+
'importAttributes',
319+
// () => throw example
320+
'throwExpressions',
321+
// You know what this is
322+
'decorators',
323+
// const { #example: example } = this;
324+
'destructuringPrivate',
325+
// using example = myExample()
326+
'explicitResourceManagement',
327+
];
311328

312329
if (shouldBeProcessedWithTypescript) {
313330
plugins.push('typescript');
@@ -318,7 +335,12 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
318335
filename: id,
319336
sourceFileName: id,
320337
presets: [[solid, { ...solidOptions, ...(options.solid || {}) }]],
321-
plugins: needHmr && !isSsr && !inNodeModules ? [[solidRefresh, { bundler: 'vite' }]] : [],
338+
plugins: needHmr && !isSsr && !inNodeModules ? [[solidRefresh, {
339+
bundler: 'vite',
340+
fixRender: true,
341+
imports: options.refresh.imports,
342+
granular: options.refresh.granular,
343+
}]] : [],
322344
ast: false,
323345
sourceMaps: true,
324346
configFile: false,

0 commit comments

Comments
 (0)