Gatsby
本页提供 JGuang UI 技术内容、中文导航与术语适配。
Note: This guide is for Gatsby with Tailwind CSS v3. For new projects, we recommend using one of the other frameworks that support Tailwind CSS v4.
Create project
Start by creating a new Gatsby project using create-gatsby:
npm init gatsby
Configure your Gatsby project to use TypeScript and Tailwind CSS
You will be asked a few questions to configure your project:
✔ What would you like to call your site?
· your-app-name
✔ What would you like to name the folder where your site will be created?
· your-app-name
✔ Will you be using JavaScript or TypeScript?
· TypeScript
✔ Will you be using a CMS?
· Choose whatever you want
✔ Would you like to install a styling system?
· Tailwind CSS
✔ Would you like to install additional features with other plugins?
· Choose whatever you want
✔ Shall we do this? (Y/n) · Yes
Edit tsconfig.json file
Add the following code to the tsconfig.json file to resolve paths:
{
"compilerOptions": {
// ...
"baseUrl": ".",
"paths": {
"@/*": [
"./src/*"
]
}
// ...
}
}
Create gatsby-node.ts file
Create a gatsby-node.ts file at the root of your project if it doesn’t already exist, and add the code below to the gatsby-node file so your app can resolve paths:
import * as path from "path"
export const onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
"@/components": path.resolve(__dirname, "src/components"),
"@/lib/utils": path.resolve(__dirname, "src/lib/utils"),
},
},
})
}
Run the CLI
Run the JGuang UI Registry init command to set up your project:
Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.
That's it
You can now start adding components to your project.
Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.
The command above will add the Button component to your project. You can then import it like this:
import { Button } from "@/components/ui/button"
export default function Home() {
return (
<div>
<Button>Click me</Button>
</div>
)
}
来源: installation/gatsby.mdx
JGuang UI 技术文档。