简体中文 | English
注:中文用户可以点击上方链接查看中文版本的文档。
Custom Template Generator is a VS Code extension designed to streamline your development process by automating the creation of repetitive file structures. It's particularly useful for developers who frequently create components or modules with a consistent file structure.
It includes common Next.js file types (such as page, layout, template, error, not-found, route, global-error, middleware, etc.) to accelerate Next.js application development.
Imagine you're developing a React application and often need to create new components. Each component typically requires:
- A folder with the component name (e.g., "Avatar")
- An index.ts file for exporting
- A main component file (e.g., Avatar.tsx)
The structure would look like this:
Avatar/
├── index.ts
└── Avatar.tsx
Manually creating this structure for each new component can be time-consuming. This extension allows you to create a template for this structure and generate it with just a few clicks, saving valuable development time.
- Quickly create custom file and folder structures
- Configure and manage reusable templates
- Built-in Next.js templates (more frameworks will be supported in the future)
- Support for placeholders in file names and contents
- Open VS Code
- Go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X)
- Search for "Custom Template Generator"
- Click the "Install" button
Submenu Explanation:
App Router
: Create a Next.js page with customizable files, default creates Page, Layout, Loading, ErrorCustom Structure
: Quickly add desired files in an existing folder, optional files include: Page, Layout, Loading, Error, NotFound, Middleware, Global Error, RoutePage
: Create a page.tsx fileLoading
: Create a loading.tsx fileLayout
: Create a layout.tsx fileTemplate
: Create a template.tsx fileError
: Create an error.tsx fileNot Found
: Create a not-found.tsx fileMiddleware
: Create a middleware.ts fileGlobal Error
: Create a global-error.tsx fileRoute
: Create a route.ts fileDefault
: Create a default.tsx file
- Open VS Code
- Go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X)
- Search for "Custom Template Generator"
- Click the "Install" button
- Open the command palette (Ctrl+Shift+P or Cmd+Shift+P)
- Type "Configure Custom Templates" and select the command
- In the opened settings page, configure the
customTemplateGenerator.templates
setting - Add your templates, each template should have
name
andfiles
properties
Note: If you want to use a sample code as a template, you can select the file, right-click, choose
Copy Formatted Code
, and paste it into the settings.
"customTemplateGenerator.templates": [
{
"name": "React Component",
"files": [
{
"name": "index.ts",
"content": "export * from './{{componentName}}'",
},
{
"name": "{{componentName}}.tsx",
"content": "export function {{componentName}}() { return <div /> }"
}
]
}
]
- Right-click in the folder to open the context menu
- Click
Create Custom Structure
- In the opened settings page, select the template you want
- Enter the component name and press
Enter
to confirm
Note: If you want to use a sample code as a template, you can select the file, right-click, choose
Copy Formatted Code
, and paste it into the settings.