Skip to content

Commit

Permalink
Merge pull request #142 from solidjs/refresh-api
Browse files Browse the repository at this point in the history
Add new `refresh` config
  • Loading branch information
ryansolid authored Feb 5, 2024
2 parents 9b59fdc + c7d6323 commit 4990bab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 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.2",
"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.

30 changes: 26 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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 @@ -307,7 +312,19 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {

return extensionOptions.typescript;
});
const plugins: NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['plugins']> = ['jsx']
const plugins: NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['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');
Expand All @@ -318,7 +335,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 4990bab

Please sign in to comment.