Quick Start
Try Minze online
Quickly check out what's Minze all about. You can try Minze in a Sandbox on on StackBlitz by selecting one of the links below.
| JavaScript | TypeScript |
|---|---|
| vite | vite-ts |
| storybook | storybook-ts |
Scaffolding a project
The easiest way to get started locally is to scaffold a new Minze dev environment. It comes with everything you need to develop custom web components and publish them to npm.
Minze requires Node.js version >=
16.0.0
Follow these steps in your command line to get started.
bash
$ npm create minze@latest my-project -- --template vite
$ cd my-project
$ npm installbash
$ yarn create minze my-project --template vite
$ cd my-project
$ yarn installbash
$ pnpm create minze my-project -- --template vite
$ cd my-project
$ pnpm installbash
$ bun create minze my-project --template vite
$ cd my-project
$ bun installCreating a component
- In the root directory of your project start the development server and open the
http://localhost:5173URL.
bash
$ npm run devbash
$ yarn devbash
$ pnpm run devbash
$ bun run dev- Navigate to the
src/libdirectory and create a newnew-element.jsfile. Thelibdirectory is where all of your web components live. During development all of them are auto-registered and ready to use.
TIP
You can also use sub-directories inside the lib directory e.g. lib/sub-dir/new-element.js
src/
└─ lib/
├─ ...
└─ new-element.js // [!code ++]- Paste the following code into the file. The component will be auto-registered with dash-case naming
new-elementinferred from the class nameNewElement.
WARNING
Keep in mind to name your component classes in PascalCase, otherwise the auto-inferrence from class to dash-case element name will not work.
js
import { MinzeElement } from 'minze'
export class NewElement extends MinzeElement {
// html template
html = () => `<div>My very own component!</div>`
// scoped stylesheet
css = () => `
div {
background: rgb(55 245 220);
color: rgb(50 50 50);
padding: 1rem;
}
`
}- Create a
preview.dev.htmlfile in thesrcdirectory (by default, git won't track this file). The file is injected into the preview during dev runtime and is what you see on the screen when you are running the dev task, if nopreview.dev.htmlfile is present, it falls back topreview.html(which is tracked by git).
src/
├─ ...
├─ preview.dev.html // [!code ++]
└─ preview.html- Add your element to
preview.dev.html. This file is essentially a little sandbox for trying out and previewing your components.
html
<new-element></new-element>- Profit. Your component/element should be displayed in the browser.
Next steps:
- Add HTML/CSS Syntax Highlighting with VS Code Plugin.
- Learn how to publish and use your components.
- Learn how to use Minze with TypeScript.