Back to Moon

Solid example

website/docs/guides/examples/solid.mdx

2.2.41.7 KB
Original Source

import AddDepsTabs from '@site/src/components/AddDepsTabs';

Solid (also known as SolidJS) is a JavaScript framework for building interactive web applications. Because of this, Solid is an application or library concern, and not a build system one, since the bundling of Solid is abstracted away through the application or a bundler.

With that being said, we do have some suggestions on utilizing Solid effectively in a monorepo. To begin, install Solid to a project.

<AddDepsTabs dep="solid-js" package="<project>" />

Setup

Solid utilizes JSX for rendering markup, which requires babel-preset-solid for parsing and transforming. To enable the preset for the entire monorepo, add the preset to a root babel.config.js, otherwise add it to a .babelrc.js in each project that requires it.

js
module.exports = {
  presets: ['solid'],
};

TypeScript integration

For each project using Solid, add the following compiler options to the tsconfig.json found in the project root.

json
{
  "compilerOptions": {
    "jsx": "preserve",
    "jsxImportSource": "solid-js"
  }
}

Vite integration

If you're using a Vite powered application (Solid Start or starter templates), you should enable vite-plugin-solid instead of configuring Babel. Be sure to read our guide on Vite as well!

js
import { defineConfig } from 'vite';
import solidPlugin from 'vite-plugin-solid';

export default defineConfig({
  // ...
  plugins: [solidPlugin()],
});