https://github.com/josef-friedrich/js-boilerplate
https://github.com/josef-friedrich/js-boilerplate
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/josef-friedrich/js-boilerplate
- Owner: Josef-Friedrich
- Created: 2023-12-27T07:41:38.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-22T20:04:50.000Z (5 months ago)
- Last Synced: 2025-02-22T21:18:54.615Z (5 months ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://npmjs.com/package/express)
# Formating
https://prettier.io/
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
# Build
`rimraf ./dist && tsc --project tsconfig.build.json`
`tsconfig.build.json`
```json
{
"extends": "./tsconfig.json",
"exclude": [
"src/**/*.test.ts"
]
}
```## Path aliases, for example `@/*`
```json
{
"scripts": {
"build:typescript": "tsc --project tsconfig.build.json && tsc-alias"
}
}
````tsconfig.json`
```json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
````vitest.config.ts`
```ts
import { defineConfig } from 'vitest/config'export default defineConfig({
test: {
alias: {
'@/': new URL('./src/', import.meta.url).pathname
}
}
})
```Run test not including `#slow`
`--testNamePattern '^((?!#slow).)*$'`
## Require main
```ts
if (require.main === module) {
// this module was run directly from the command line as in node xxx.js
} else {
// this module was not run directly from the command line and probably loaded by something else
}
```ESM version:
https://stackoverflow.com/a/72206110
```ts
const isMainModule = import.meta.url.endsWith(process.argv[1])if (isMainModule) {
console.log('main')
}
```# npm-run-all2
```json
{
"scripts": {
"build": "run-s build:openapi build:typescript build:json-schema build:union-types"
}
}
```## Typescript
### Derive union type from tuple/array values
https://stackoverflow.com/a/45257357
```ts
export const colorNames = [
'white',
'yellow',
'orange',
'red',
'brown',
'green',
'blue',
'purple',
'black'
] as constexport type ColorName = (typeof colorNames)[number]
```