October 2, 2023
One-off Javascript project set-up
Most of my Javascript projects start with SvelteKit: pnpm create svelte@latest project_name. When they don’t, it’s usually a one-off script or scraping task. Here’s some minimal set-up that makes life easier.
mkdir project_name && cd project_name && pnpm init Add "type": "module" to package.json.
For typechecking, add a jsconfig.json with:
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"moduleResolution": "node",
"module": "esnext",
"target": "esnext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true
},
"exclude": ["node_modules"]
} Tell VSCode to format on save by adding a .vscode/settings.json with:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
} Assuming you have Prettier installed globally, add a .prettierrc to configure formatting with:
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none"
} What else? Playwright and SQLite, more often than not:
pnpm add @playwright/test better-sqlite3 In a larger project I would use Vitest for unit tests, but Playwright is good enough for a few in a *.test.js or *.spec.js file. Its default config usually suffices without creating a playwright.config.ts.