I want to use Lit on an existing project which is not yet using npm.
I got to https://lit.dev/docs/tools/adding-lit/ but doesn’t say how to tool / bundle the components.
lib/components/my-element.ts
Is there some path to go about using something like webpack or even newer, vite ?
If you want to integrate Lit into an existing project, you can definitely use bundlers like Webpack or Vite.
But am going to give you that for Vite
only
Here’s how you can set up Vite for your project:
- Install Vite
npm install --save-dev vite
- Create a Vite config, add a
vite.config.js
import { defineConfig } from 'vite';
export default defineConfig({
build: {
outDir: 'dist',
},
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
},
});
- Update your
tsconfig.json
for transpiling
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"lib": ["ESNext", "DOM"],
"declaration": true,
"sourceMap": true
}
}
- Add start and build scripts to your
package.json
{
"scripts": {
"dev": "vite",
"build": "vite build"
}
}
- Run Vite
- For development
npm run dev
- For a production build
npm run build
Good luck
Thanks a bunch. This solved my day.