Skip to content

feat(ts): almost enable TypeScript in the playground #5384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/lwc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@
"./synthetic-shadow": "./synthetic-shadow.js",
"./template-compiler": "./template-compiler.js",
"./wire-service": "./wire-service.js"
},
"volta": {
"extends": "../../package.json"
}
}
4 changes: 4 additions & 0 deletions playground/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ $ npm run dev # Get app server running
$ npm run build # Build app in production mode
$ npx serve # Serve the app (after running `npm run build`).
```

## TypeScript

To enable TypeScript in the LWC playground, add `@rollup/plugin-typescript` to the list of plugins in `rollup.config.js`. The playground has a pre-configured `tsconfig.json` that allows both JS and TS files to be used.
4 changes: 4 additions & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"devDependencies": {
"@lwc/rollup-plugin": "8.20.0",
"@rollup/plugin-replace": "^6.0.2",
"@rollup/plugin-typescript": "^12.1.2",
"lwc": "8.20.0",
"rollup": "^4.40.0",
"rollup-plugin-livereload": "^2.0.5",
Expand All @@ -24,5 +25,8 @@
]
}
}
},
"volta": {
"extends": "../package.json"
}
}
2 changes: 2 additions & 0 deletions playground/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import lwc from '@lwc/rollup-plugin';
import replace from '@rollup/plugin-replace';
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
// import typescript from '@rollup/plugin-typescript'; // Only required for TypeScript projects

const __ENV__ = process.env.NODE_ENV ?? 'development';

Expand All @@ -15,6 +16,7 @@ export default (args) => {
},

plugins: [
// typescript(), // Only required for TypeScript projects
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it cause issues if we just left it on?

Does it cause issues for .js only components?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't cause issues, but I wanted to be sure that we're sticking to only the truly minimal playground for the default use case.

replace({
'process.env.NODE_ENV': JSON.stringify(__ENV__),
preventAssignment: true,
Expand Down
12 changes: 12 additions & 0 deletions playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// A tsconfig.json file is only required for TypeScript projects
{
"compilerOptions": {
"allowJs": true,
"experimentalDecorators": false, // Required for LWC decorators to work
"module": "nodenext",
"noEmit": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext" // Required for LWC decorators to work
}
}