├── src ├── index.ts ├── vite-env.d.ts └── sum.ts ├── .lintstagedrc ├── bun.lockb ├── .github ├── logo.png ├── FUNDING.yml └── renovate.json ├── .prettierignore ├── CHANGELOG.md ├── test └── sum.test.ts ├── .npmignore ├── dts-bundle-generator.config.ts ├── .gitignore ├── .prettierrc ├── index.html ├── tsconfig.json ├── LICENSE.md ├── vite.config.ts ├── favicon.svg ├── package.json └── README.md /src/index.ts: -------------------------------------------------------------------------------- 1 | export { sum } from "./sum"; 2 | -------------------------------------------------------------------------------- /src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /.lintstagedrc: -------------------------------------------------------------------------------- 1 | { 2 | "./**/*.{ts,html,json}": "npm run format" 3 | } 4 | -------------------------------------------------------------------------------- /bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matronator/vite-ts-lib-starter/HEAD/bun.lockb -------------------------------------------------------------------------------- /.github/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matronator/vite-ts-lib-starter/HEAD/.github/logo.png -------------------------------------------------------------------------------- /src/sum.ts: -------------------------------------------------------------------------------- 1 | export function sum(a: number, b: number): number { 2 | return a + b; 3 | } 4 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .history 2 | .husky 3 | .vscode 4 | coverage 5 | dist 6 | node_modules 7 | .github 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to the "vite-ts-lib-starter" project will be documented in this file. 4 | 5 | ## [0.1.0] - 2024-06-29 6 | 7 | - Initial release 8 | -------------------------------------------------------------------------------- /test/sum.test.ts: -------------------------------------------------------------------------------- 1 | import { assert, describe, it } from 'vitest'; 2 | import { sum } from '../src/index'; 3 | 4 | describe("construct", () => { 5 | it("should return 3", () => { 6 | assert.equal(sum(1, 2), 3); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | coverage 2 | test 3 | node_modules 4 | *.log 5 | .lintstagedrc 6 | .prettierignore 7 | .prettierrc 8 | favicon.ico 9 | vite.config.js 10 | dts-bundle-generator.config.json 11 | tsconfig.json 12 | index.html 13 | .vscode 14 | .github 15 | -------------------------------------------------------------------------------- /dts-bundle-generator.config.ts: -------------------------------------------------------------------------------- 1 | const config = { 2 | entries: [ 3 | { 4 | filePath: "./src/index.ts", 5 | outFile: "./dist/package-name.d.ts", 6 | noCheck: false, 7 | }, 8 | ], 9 | }; 10 | 11 | module.exports = config; 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | build 12 | dist 13 | dist-ssr 14 | *.local 15 | coverage 16 | 17 | # Editor directories and files 18 | .vscode/* 19 | .history/* 20 | !.vscode/extensions.json 21 | .idea 22 | .DS_Store 23 | *.suo 24 | *.ntvs* 25 | *.njsproj 26 | *.sln 27 | *.sw? 28 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "tabWidth": 4, 4 | "singleQuote": false, 5 | "trailingComma": "es5", 6 | "arrowParens": "avoid", 7 | "bracketSpacing": true, 8 | "useTabs": false, 9 | "endOfLine": "auto", 10 | "singleAttributePerLine": false, 11 | "bracketSameLine": false, 12 | "jsxSingleQuote": false, 13 | "quoteProps": "as-needed", 14 | "semi": true 15 | } 16 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [matronator] 4 | patreon: matronator 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: matronator 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://www.paypal.me/matronator', 'https://www.blockchain.com/btc/address/35VRpVQaqFWjUCnVRpGineShz76QyYgSVg'] 13 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:best-practices", 5 | ":pinOnlyDevDependencies", 6 | ":ignoreModulesAndTests", 7 | ":preserveSemverRanges", 8 | "group:all", 9 | "schedule:weekly", 10 | ":maintainLockFilesMonthly" 11 | ], 12 | "labels": ["dependencies", "renovate"], 13 | "lockFileMaintenance": { 14 | "commitMessageAction": "Update", 15 | "extends": [ 16 | "group:all" 17 | ] 18 | }, 19 | "separateMajorMinor": false, 20 | "autoApprove": true, 21 | "automerge": true, 22 | "pruneBranchAfterAutomerge": true, 23 | "automergeType": "branch" 24 | } 25 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "rootDir": ".", 4 | "paths": { 5 | "@/*": ["./src/*"], 6 | "@@/*": ["./*"] 7 | }, 8 | "target": "ESNext", 9 | "useDefineForClassFields": true, 10 | "module": "ESNext", 11 | "lib": ["ESNext", "DOM"], 12 | "moduleResolution": "Node", 13 | "strict": true, 14 | "sourceMap": true, 15 | "resolveJsonModule": true, 16 | "esModuleInterop": true, 17 | "noEmit": true, 18 | "noUnusedLocals": true, 19 | "noUnusedParameters": true, 20 | "noImplicitReturns": true, 21 | "forceConsistentCasingInFileNames": true, 22 | "types": ["vite/client", "node"], 23 | "declaration": true, 24 | "declarationDir": "dist", 25 | "listEmittedFiles": true 26 | }, 27 | "include": ["src", "dist/index.d.ts"], 28 | "exclude": ["**/*.test.ts", "node_modules", "test/**", ".history/**"] 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Matronator 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import path from 'path'; 3 | import { defineConfig } from 'vite'; 4 | import packageJson from './package.json'; 5 | 6 | const getPackageName = () => { 7 | return packageJson.name; 8 | }; 9 | 10 | const getPackageNameCamelCase = () => { 11 | try { 12 | return getPackageName().replace(/-./g, char => char[1].toUpperCase()); 13 | } catch (err) { 14 | throw new Error("Name property in package.json is missing."); 15 | } 16 | }; 17 | 18 | const fileName = { 19 | es: `${getPackageName()}.esm.js`, 20 | cjs: `${getPackageName()}.cjs`, 21 | iife: `${getPackageName()}.iife.js`, 22 | }; 23 | 24 | const formats = Object.keys(fileName) as Array; 25 | 26 | export default defineConfig({ 27 | base: "./", 28 | build: { 29 | outDir: "./dist", 30 | lib: { 31 | entry: path.resolve(__dirname, "src/index.ts"), 32 | name: getPackageNameCamelCase(), 33 | formats, 34 | fileName: format => fileName[format], 35 | }, 36 | minify: 'terser', 37 | terserOptions: { 38 | keep_classnames: true, 39 | keep_fnames: true, 40 | } 41 | }, 42 | test: { 43 | globals: true, 44 | environment: "jsdom", 45 | }, 46 | resolve: { 47 | alias: [ 48 | { find: "@", replacement: path.resolve(__dirname, "src") }, 49 | { find: "@@", replacement: path.resolve(__dirname) }, 50 | ], 51 | }, 52 | }); 53 | -------------------------------------------------------------------------------- /favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "package-name", 3 | "version": "0.1.0", 4 | "author": { 5 | "name": "Author Name", 6 | "email": "author@email.com", 7 | "url": "https://website.com" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/username/repository.git" 12 | }, 13 | "main": "./dist/package-name.cjs", 14 | "module": "./dist/package-name.esm.js", 15 | "jsdelivr": "./dist/package-name.iife.js", 16 | "exports": { 17 | ".": { 18 | "require": "./dist/package-name.cjs", 19 | "import": "./dist/package-name.esm.js", 20 | "types": "./dist/package-name.d.ts" 21 | }, 22 | "./dist/": { 23 | "import": "./dist/", 24 | "require": "./dist/", 25 | "types": "./dist/" 26 | } 27 | }, 28 | "scripts": { 29 | "dev": "vite --host", 30 | "prebuild": "rm -rf dist/*", 31 | "build": "tsc && vite build", 32 | "postbuild": "dts-bundle-generator --config ./dts-bundle-generator.config.ts", 33 | "test": "vitest", 34 | "test:coverage": "vitest --coverage", 35 | "format": "prettier . --write", 36 | "upgrade": "upgradeps", 37 | "release": "npm run build && np" 38 | }, 39 | "bugs": { 40 | "url": "https://github.com/username/repository/issues" 41 | }, 42 | "description": "Package description.", 43 | "files": [ 44 | "dist", 45 | "README.md", 46 | "LICENSE.md", 47 | "CHANGELOG.md", 48 | "src", 49 | "package.json" 50 | ], 51 | "funding": [ 52 | { 53 | "type": "individual", 54 | "url": "https://support.example.com" 55 | } 56 | ], 57 | "homepage": "https://github.com/username/repository#readme", 58 | "keywords": ["some", "keywords"], 59 | "license": "MIT", 60 | "private": false, 61 | "sponsor": { 62 | "url": "https://sponsor.example.com" 63 | }, 64 | "type": "module", 65 | "types": "./dist/package-name.d.ts", 66 | "typesVersions": { 67 | "*": { 68 | "*": [ 69 | "./dist/package-name.d.ts" 70 | ] 71 | } 72 | }, 73 | "typings": "./dist/package-name.d.ts", 74 | "devDependencies": { 75 | "@types/jsdom": "^21.1.6", 76 | "@types/node": "^20.11.5", 77 | "@vitest/coverage-v8": "^1.2.1", 78 | "dts-bundle-generator": "^9.2.4", 79 | "jsdom": "^24.1.0", 80 | "lint-staged": "^15.2.0", 81 | "np": "^10.0.6", 82 | "prettier": "^3.2.4", 83 | "terser": "^5.31.1", 84 | "ts-node": "^10.9.2", 85 | "typescript": "^5.3.3", 86 | "upgradeps": "^2.0.6", 87 | "vite": "^5.0.12", 88 | "vitest": "^1.2.1" 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vite TypeScript Library Starter 2 | 3 | ![Ping Tracker logo](.github/logo.png) 4 | 5 | ![NPM Version](https://img.shields.io/npm/v/package-name) 6 | ![NPM Downloads](https://img.shields.io/npm/dw/package-name) 7 | ![npm TypeScript version](https://img.shields.io/npm/dependency-version/package-name/dev/typescript) 8 | ![Tree shaking](https://badgen.net/bundlephobia/tree-shaking/package-name) 9 | ![Dependencies](https://badgen.net/bundlephobia/dependency-count/package-name) 10 | ![npm package minimized gzipped size](https://img.shields.io/bundlejs/size/package-name) 11 | ![Commits](https://badgen.net/github/commits/username/repository) 12 | ![Issues](https://img.shields.io/github/issues/username/repository.svg) 13 | ![License](https://img.shields.io/github/license/username/repository.svg) 14 | ![Follow](https://img.shields.io/github/followers/matronator.svg?style=social&label=Follow&maxAge=2592000) 15 | ![GitHub Sponsors](https://img.shields.io/github/sponsors/matronator) 16 | 17 | A starter template to use for developing libraries with Vite and TypeScript. 18 | 19 | ## Tech-stack 20 | 21 | - [Bun](https://bunpkg.com/) - A package manager for the web (faster alternative to npm and yarn) 22 | - [Vite](https://vitejs.dev/) - A next-generation front-end tooling 23 | - [TypeScript](https://www.typescriptlang.org/) - A typed superset of JavaScript 24 | - [Vitest](https://vitest.dev/) - A test runner for Vite 25 | - [Prettier](https://prettier.io/) - An opinionated code formatter 26 | - [Renovate](https://www.mend.io/renovate/) - Automated dependency updates 27 | - [np](https://github.com/sindresorhus/np) - A better `npm publish` 28 | 29 | ## Installation 30 | 31 | 1. Clone this repository, or 32 | 2. Click on "Use this template" button, or 33 | 3. Download the repository as a ZIP file, or 34 | 4. Use [degit](https://github.com/Rich-Harris/degit), like this: 35 | 36 | ``` 37 | bunx degit matronator/vite-ts-lib-starter my-new-library 38 | ``` 39 | 40 | ## After installation 41 | 42 | 1. Change the `package.json` file to match your library's name, description, author, etc. 43 | 2. Change the `outFile` field in the `dts-bundle-generator.config.js` file to match your library's name. 44 | 3. Replace the logo with your own. 45 | 4. Modify `FUNDING.yml` in the `.github` folder with your own values or remove it completely. 46 | 5. Replace the `README.md` file with your own. 47 | 6. Change the name in the `LICENSE.md` file. 48 | 7. Replace the `CHANGELOG.md` file with your own. 49 | 8. Start creating your library in the `src` folder. 50 | 9. Write some tests in the `tests` folder. 51 | 10. When you're ready to publish your library, run `npm run build` to generate the production files. 52 | 11. Publish your library to npm with either `npm publish`, or `npm run release` to use `np` for a better publishing experience. 53 | --------------------------------------------------------------------------------