From 4ef6a4f845a84e49ee91706387706c45ef928234 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Fri, 12 Feb 2021 20:27:28 +0100 Subject: [PATCH] :sparkles: Aliasing solid-js for solid-js/dev in dev mode --- playground/index.tsx | 17 ++++------------- src/index.ts | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/playground/index.tsx b/playground/index.tsx index 240535c..75f6a62 100644 --- a/playground/index.tsx +++ b/playground/index.tsx @@ -1,8 +1,8 @@ import { createSignal, lazy } from 'solid-js'; -import { render } from 'solid-js/web'; import { Link } from 'solid-app-router'; import { MetaProvider } from 'solid-meta'; import { Router, Route, RouteDefinition } from 'solid-app-router'; +import { createApp } from 'solid-utils'; import Home from './pages'; @@ -23,23 +23,14 @@ const App = () => { return ( <> Home - About!!! - + About!!! + ); }; -const dispose = render( - () => ( - - - - - - ), - document.getElementById('app'), -); +const dispose = createApp(App).use(MetaProvider).use(Router, { routes }).mount('#app'); if (import.meta.hot) { import.meta.hot.accept(); diff --git a/src/index.ts b/src/index.ts index 475d42a..fb0113a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,9 @@ -import { transformAsync, TransformOptions } from '@babel/core'; -import solid from 'babel-preset-solid'; import { Plugin } from 'vite'; +import solid from 'babel-preset-solid'; +import { transformAsync, TransformOptions } from '@babel/core'; interface Options { + dev: boolean; moduleName: string; builtIns: string[]; delegateEvents: boolean; @@ -14,13 +15,20 @@ interface Options { generate: 'dom' | 'ssr'; } -export default function solidPlugin(options?: Partial): Plugin { +export default function solidPlugin(options: Partial = {}): Plugin { let needHmr = false; return { name: 'solid', - config() { + config(_, { command }) { + const replaceDev = options.dev !== false; + + const alias = + command === 'serve' && replaceDev + ? [{ find: /^solid-js$/, replacement: 'solid-js/dev' }] + : []; + return { /** * We only need esbuild on .ts or .js files. @@ -29,9 +37,10 @@ export default function solidPlugin(options?: Partial): Plugin { esbuild: { include: /\.ts$/ }, resolve: { dedupe: ['solid-js', 'solid-js/web'], + alias, }, optimizeDeps: { - include: ['solid-js/web'], + include: ['solid-js/dev', 'solid-js/web'], }, }; },