Skip to content

Commit

Permalink
♻️ Refactor a bit the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
amoutonbrady committed Feb 17, 2021
1 parent 2af8a39 commit 481f74b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Plugin } from 'vite';
import solid from 'babel-preset-solid';
import { transformAsync, TransformOptions } from '@babel/core';

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

async transform(source, id) {
async transform(source, id, ssr) {
if (!/\.[jt]sx/.test(id)) return null;

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

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

const opts: TransformOptions = {
filename: id,
presets: [[solid, solidOptions]],
presets: [[require('babel-preset-solid'), solidOptions]],
};

if (id.includes('tsx')) {
Expand Down

0 comments on commit 481f74b

Please sign in to comment.