Adding Lit to an existing project
Lit doesn't require any specialized tools, and Lit components work in any JavaScript framework or with any server templating system or CMS, so Lit is ideal for adding to existing projects and applications.
Install from npm
Permalink to “Install from npm”First, install the lit
package from npm:
If you are not already using npm to manage JavaScript dependencies, you will have to set up your project first. We recommend the npm CLI.
Add a component
Permalink to “Add a component”You can create a new element anywhere in your project's sources:
lib/components/my-element.ts
Use your component
Permalink to “Use your component”How you use a component depends on your project and the libraries or frameworks it uses. You can use your component in HTML, with DOM APIs, or in template languages:
Plain HTML
Permalink to “Plain HTML”
JSX is a very common templating language. In JSX, lower-case element names create HTML elements, which is what Lit components are. Use the tag name you specified in the @customElement()
decorator:
Framework templates
Permalink to “Framework templates”Most JavaScript frameworks have great support for web components and Lit. Just import your element definition and use the element tag names in your templates.
Next steps
Permalink to “Next steps”At this point, you should be able to build and run your project and see the "Hello from MyElement!" message.
If you're ready to add features to your component, head over to Components to learn about building your first Lit component, or Templates for details on writing templates.
For details on building projects, including some sample Rollup configurations, see Building for production.