Skip to content

Commit

Permalink
Add new refresh config
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Jan 24, 2024
1 parent 9b59fdc commit 92a5533
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@types/babel__core": "^7.20.4",
"babel-preset-solid": "^1.8.4",
"merge-anything": "^5.1.7",
"solid-refresh": "^0.6.3",
"solid-refresh": "^0.7.0",
"vitefu": "^0.2.5"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { readFileSync } from 'fs';
import { mergeAndConcat } from 'merge-anything';
import { createRequire } from 'module';
import solidRefresh from 'solid-refresh/babel';
// TODO use proper path
import type { Options as RefreshOptions } from 'solid-refresh/dist/types/src/babel/core/types';
import { createFilter } from 'vite';
import type { Alias, AliasOptions, Plugin, FilterPattern } from 'vite';
import { crawlFrameworkPkgs } from 'vitefu';
Expand Down Expand Up @@ -51,6 +53,7 @@ export interface Options {
* This will inject HMR runtime in dev mode. Has no effect in prod. If
* set to `false`, it won't inject the runtime in dev.
*
* @deprecated use `refresh` instead
* @default true
*/
hot: boolean;
Expand Down Expand Up @@ -142,6 +145,8 @@ export interface Options {
*/
builtIns?: string[];
};

refresh: Omit<RefreshOptions & { disabled: boolean }, 'bundler' | 'fixRender'>;
}

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

configResolved(config) {
needHmr = config.command === 'serve' && config.mode !== 'production' && options.hot !== false;
needHmr = config.command === 'serve' && config.mode !== 'production' && (options.hot !== false || !options.refresh.disabled);
},

resolveId(id) {
Expand Down Expand Up @@ -318,7 +323,12 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
filename: id,
sourceFileName: id,
presets: [[solid, { ...solidOptions, ...(options.solid || {}) }]],
plugins: needHmr && !isSsr && !inNodeModules ? [[solidRefresh, { bundler: 'vite' }]] : [],
plugins: needHmr && !isSsr && !inNodeModules ? [[solidRefresh, {
bundler: 'vite',
fixRender: true,
imports: options.refresh.imports,
granular: options.refresh.granular,
}]] : [],
ast: false,
sourceMaps: true,
configFile: false,
Expand Down

0 comments on commit 92a5533

Please sign in to comment.