Skip to content

Commit 481f74b

Browse files
committed
♻️ Refactor a bit the plugin
1 parent 2af8a39 commit 481f74b

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Plugin } from 'vite';
2-
import solid from 'babel-preset-solid';
32
import { transformAsync, TransformOptions } from '@babel/core';
43

54
interface Options {
@@ -41,14 +40,13 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
4140
needHmr = config.command === 'serve' && !config.isProduction;
4241
},
4342

44-
async transform(source, id) {
43+
async transform(source, id, ssr) {
4544
if (!/\.[jt]sx/.test(id)) return null;
4645

4746
let solidOptions: { generate: 'ssr' | 'dom'; hydratable: boolean };
4847

4948
if (options.ssr) {
50-
// This is a ugly hack that doesn't work really well..
51-
if (globalThis._SOLID_SSR) {
49+
if (ssr) {
5250
solidOptions = { generate: 'ssr', hydratable: true };
5351
} else {
5452
solidOptions = { generate: 'dom', hydratable: true };
@@ -59,7 +57,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
5957

6058
const opts: TransformOptions = {
6159
filename: id,
62-
presets: [[solid, solidOptions]],
60+
presets: [[require('babel-preset-solid'), solidOptions]],
6361
};
6462

6563
if (id.includes('tsx')) {

0 commit comments

Comments
 (0)