Skip to content

Commit a45498b

Browse files
authored
Initial commit
0 parents  commit a45498b

14 files changed

Lines changed: 7720 additions & 0 deletions

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
dist/
3+
env.d.ts
4+
```

.eslintrc.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
es2021: true,
5+
node: true
6+
},
7+
extends: [
8+
// By extending from a plugin config, we can get recommended rules without having to add them manually.
9+
"eslint:recommended",
10+
"plugin:import/recommended",
11+
"plugin:@typescript-eslint/recommended",
12+
// This disables the formatting rules in ESLint that Prettier is going to be responsible for handling.
13+
// Make sure it's always the last config, so it gets the chance to override other configs.
14+
"eslint-config-prettier",
15+
"prettier"
16+
],
17+
settings: {
18+
// Tells eslint how to resolve imports
19+
"import/resolver": {
20+
alias: {
21+
map: [["@", "./src"]],
22+
extensions: [".ts", ".js", ".jsx", ".tsx", ".json"]
23+
},
24+
node: {
25+
paths: ["./src"],
26+
extensions: [".js", ".jsx", ".ts", ".tsx"]
27+
}
28+
},
29+
"import/parsers": {
30+
"@typescript-eslint/parser": [".ts", ".tsx"]
31+
}
32+
},
33+
rules: {
34+
// Add your own rules here to override ones from the extended configs.
35+
"@typescript-eslint/no-explicit-any": "warn"
36+
},
37+
overrides: [
38+
{
39+
files: ["**/__mocks__/*", "**/*.{test,tests}.{ts,tsx}"], // Feels unnecessary to enforce these rules in tests
40+
rules: {
41+
"@typescript-eslint/no-unused-vars": 0,
42+
"@typescript-eslint/no-explicit-any": 0
43+
}
44+
}
45+
]
46+
};

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
coverage

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
dist/
3+
coverage/

.prettierrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
trailingComma: "none",
3+
tabWidth: 2,
4+
semi: true,
5+
singleQuote: false,
6+
printWidth: 120,
7+
bracketSpacing: true,
8+
endOfLine: "lf"
9+
};

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"workbench.colorTheme": "Darcula",
3+
"workbench.iconTheme": "material-icon-theme",
4+
"editor.fontFamily": "JetBrains Mono",
5+
"editor.defaultFormatter": "esbenp.prettier-vscode",
6+
"editor.formatOnSave": true,
7+
"typescript.tsdk": "node_modules/typescript/lib"
8+
}

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# vite-node-ts-starter
2+
3+
- [vite-node](https://github.com/vitest-dev/vitest/tree/main/packages/vite-node)
4+
- [esbuild](https://esbuild.github.io/)
5+
- [eslint](https://eslint.org/)
6+
- [prettier](https://prettier.io/)
7+
- [typescript](https://www.typescriptlang.org/)
8+
- [vitest](https://vitest.dev/)
9+
10+
A few things to understand
11+
12+
1. building with esbuild
13+
2. building with the typescript compiler
14+
15+
Importing the package.json makes the tsc compiler bundle the /src folder into the /dist folder. To keep these two build options working together esbuild is configured to nest the output in /src folder too.
16+
17+
Have a play around with the configuration and build options to suit the project.
18+
19+
This is a work in progress template and welcome to feedback.
20+
21+
## Requirements
22+
23+
This project requires node.js to be installed. This project uses volta to manage node versions.
24+
25+
To install volta run the following command in the terminal.
26+
27+
```
28+
curl https://get.volta.sh | bash
29+
```
30+
31+
### ESM Node
32+
33+
https://www.typescriptlang.org/docs/handbook/esm-node.html
34+
35+
### Install
36+
37+
Build and install the package globally so you have access in your cli terminal.
38+
39+
1. build `npm run build:es`
40+
2. install `npm install -g .`
41+
42+
Then test the package is working and installed by calling the package name `pkg-name` in your terminal.
43+
44+
### Testing
45+
46+
This project uses [vitest](https://vitest.dev/) for testing.
47+
48+
1. run the unit tests with `npm run test`
49+
50+
It's also recommended to install the [vitest extension for vscode](https://marketplace.visualstudio.com/items?itemName=ZixuanChen.vitest-explorer).

build.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { build } from "esbuild";
2+
3+
// https://janessagarrow.com/blog/typescript-and-esbuild/
4+
const sharedConfig = {
5+
entryPoints: ["src/index.ts"],
6+
bundle: true,
7+
minify: true,
8+
sourcemap: true,
9+
target: "node16"
10+
};
11+
12+
build({
13+
...sharedConfig,
14+
platform: "node",
15+
outfile: "dist/src/index.js",
16+
format: "cjs"
17+
});
18+
19+
build({
20+
...sharedConfig,
21+
outfile: "dist/src/index.esm.js",
22+
platform: "node",
23+
format: "esm"
24+
});

0 commit comments

Comments
 (0)