diff --git a/package.json b/package.json index a2cb666..6c9de7e 100644 --- a/package.json +++ b/package.json @@ -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.2", "vitefu": "^0.2.5" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c7b90b8..e8da4a4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,8 +21,8 @@ dependencies: specifier: ^5.1.7 version: 5.1.7 solid-refresh: - specifier: ^0.6.3 - version: 0.6.3(solid-js@1.8.5) + specifier: ^0.7.2 + version: 0.7.2(solid-js@1.8.5) vitefu: specifier: ^0.2.5 version: 0.2.5(vite@5.0.0) @@ -2503,8 +2503,8 @@ packages: csstype: 3.1.3 seroval: 0.12.4 - /solid-refresh@0.6.3(solid-js@1.8.5): - resolution: {integrity: sha512-F3aPsX6hVw9ttm5LYlth8Q15x6MlI/J3Dn+o3EQyRTtTxidepSTwAYdozt01/YA+7ObcciagGEyXIopGZzQtbA==} + /solid-refresh@0.7.2(solid-js@1.8.5): + resolution: {integrity: sha512-dY3LuXIMCKZZaX3bczdOFQyfUxGWUwcUJgVZeo18tGvZqUTvfacy7lCR2iWR627AvbQUcCrdN6w3GmZicglPjA==} peerDependencies: solid-js: ^1.3 dependencies: diff --git a/src/index.ts b/src/index.ts index 03fe776..a94e8c4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,10 @@ 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/babel'; +import type { Alias, AliasOptions, FilterPattern, Plugin } from 'vite'; import { createFilter } from 'vite'; -import type { Alias, AliasOptions, Plugin, FilterPattern } from 'vite'; import { crawlFrameworkPkgs } from 'vitefu'; const require = createRequire(import.meta.url); @@ -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; @@ -142,6 +145,8 @@ export interface Options { */ builtIns?: string[]; }; + + refresh: Omit; } function getExtension(filename: string): string { @@ -255,7 +260,7 @@ export default function solidPlugin(options: Partial = {}): 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) { @@ -307,7 +312,19 @@ export default function solidPlugin(options: Partial = {}): Plugin { return extensionOptions.typescript; }); - const plugins: NonNullable['plugins']> = ['jsx'] + const plugins: NonNullable['plugins']> = [ + 'jsx', + // import { example } from 'example' with { example: true }; + 'importAttributes', + // () => throw example + 'throwExpressions', + // You know what this is + 'decorators', + // const { #example: example } = this; + 'destructuringPrivate', + // using example = myExample() + 'explicitResourceManagement', + ]; if (shouldBeProcessedWithTypescript) { plugins.push('typescript'); @@ -318,7 +335,12 @@ export default function solidPlugin(options: Partial = {}): 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,