Skip to content

Commit

Permalink
chore: mvp
Browse files Browse the repository at this point in the history
  • Loading branch information
Shakeskeyboarde committed May 9, 2024
1 parent 804e59c commit 638bb64
Show file tree
Hide file tree
Showing 7 changed files with 726 additions and 37 deletions.
55 changes: 55 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Contributing

Thanks for your interest in contributing to this project! We welcome any contributions, including bug reports, feature requests, questions, discussions, code, documentation, tests, or anything else that you think would improve the project.

PRs for bug fixes can be submitted directly, but PRs for new features should be discussed in an issue first.

Before you get started, please read the following guidelines.

## Setup

1. Fork the repository on GitHub and clone your fork to your local machine.
2. Run `corepack enable` at the repo root to enable Corepack and PNPM. This repo is a PNPM monorepo, so all package manager commands will be PNPM commands.
3. Run `pnpm install` at the repo root to restore all dependencies.
4. Run `pnpm build` at the repo root to build all packages.
5. Run `pnpm test` at the repo root to run all tests.

## Style

Please use the following style guide when contributing to this project.

- Use 2 spaces for indentation.
- Use single quotes for strings.
- Use `camelCase` for variable and function names.
- Use `PascalCase` for class names.
- Use `kebab-case` for filenames.
- Name the file after the class or function it exports.
- Export only one class or function per file.
- Exporting supporting types is also fine.
- Wrap all code at 120 characters (max).
- Use Expect (instead of Assert) syntax for tests.

This project uses ESLint to check style, but not all rules are strictly enforced, and you should use your best judgment when contributing.

If you use VSCode (recommended), you can install the [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) to get real-time feedback on your code.

Useful VSCode [Project Settings](.vscode/settings.json):

```json
{
"explorer.excludeGitIgnore": true,
"eslint.format.enable": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.tabSize": 2,
}
```

## Test

Please add/modify tests for any code changes you make. Generally, we want test files to be fairly self contained, so please keep any utilities, fixtures, or constants in the same file as the tests that use them. Test files should be placed in the `__tests__` directory.

## Merge

Once you open a PR, it will be reviewed by a maintainer. If the PR is approved, it will be merged. If the PR is not approved, the maintainer will leave a comment explaining why, and possible changes that could be made to get the PR approved.

After the PR is merged, it will be released in the next version of the project. The next version may not be released immediately, and it may contain changes for several PRs. We will try to release new version in a timely manner.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Vite Plugin Auto Lib

Vite plugin that configures sane defaults for building libraries.

## Getting Started

Install the plugin:

```sh
npm install vite-plugin-auto-lib --save-dev
```

Add the plugin to your `vite.config.js`:

```ts
import { defineConfig } from 'vite';
import { lib } from 'vite-plugin-auto-lib';

export default defineConfig({
plugins: [lib()]
});
```

As long as you have a [common entrypoint](#common-entrypoints) (eg. `src/index.ts`), this should be a working configuration for most libraries.

Only [defaults](#config-defaults) are provided, so any configuration set by earlier plugins or by the user will be left as-is.

```ts
export default defineConfig({
plugins: [lib()],
// Override the auto-detected lib entry.
build: {
lib: {
entry: 'src/foo.ts',
}
}
});
```

## Common Entrypoints

The plugin will auto detect entrypoints with the following prefixes and extensions:

- Prefixes: `index`, `bin`, `main`, `src/index`, `src/bin`, `src/main`
- Extensions: `.ts`, `.tsx`, `.mts`, `.cts`, `.js`, `.jsx`, `.mjs`, `.cjs`

Multiple entrypoints can be detected. However, if the same prefix exists with multiple extensions, only one will be detected as an entrypoint. The extensions are listed in order of priority, with the highest priority first. Therefore, if `index.ts` and `index.tsx` both exist, then `index.ts` will be detected.

## Config Defaults

- `build.target`: `'esnext'`
- `build.sourcemap`: `true`
- `build.lib.formats`: Auto-detected from the `type` field in the nearest
`package.json` file.
- `build.lib.fileName`: `'[name]'`
- `build.lib.entry`: Auto-detected at the Vite `root` from a list of common
entry points.
- `build.rollupOptions.treeshake`: `false`
- `build.rollupOptions.external`: Externalizes NodeJS built-ins, native
modules, and production dependencies.
- `build.rollupOptions.output.preserveModules`: `true`

## Recommended Supplemental Plugins

- [vite-plugin-checker](https://www.npmjs.com/package/vite-plugin-checker)
- Type checking.
- [vite-plugin-dts](https://www.npmjs.com/package/vite-plugin-dts)
- Type declarations.
- [vite-plugin-bin](https://www.npmjs.com/package/vite-plugin-bin)
- Bin script helper.
- [vite-plugin-data](https://www.npmjs.com/package/vite-plugin-data)
- Build-time data injection.
- [rollup-plugin-node-externals](https://www.npmjs.com/package/rollup-plugin-node-externals)
- More complete and configurable externalization.
16 changes: 0 additions & 16 deletions index.html

This file was deleted.

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"private": true,
"name": "UNTITLED",
"description": "",
"version": "0.0.0-prerelease",
"name": "vite-plugin-auto-lib",
"description": "Vite plugin that configures sane defaults for building libraries.",
"version": "0.0.1",
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/Shakeskeyboarde/UNTITLED.git"
"url": "https://github.com/Shakeskeyboarde/vite-plugin-auto-lib.git"
},
"scripts": {
"start": "vite",
Expand All @@ -15,11 +15,10 @@
"open-coverage": "open out/coverage/index.html"
},
"files": [
"lib"
"dist"
],
"publishConfig": {
"access": "public",
"tag": "prerelease"
"access": "public"
},
"type": "module",
"types": "./dist/index.d.ts",
Expand All @@ -35,9 +34,11 @@
"@vitest/coverage-v8": "^1.6.0",
"eslint": "^8",
"eslint-config-rational": "^5.0.13",
"rollup-plugin-node-externals": "^7.1.2",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vite-plugin-checker": "^0.6.4",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.6.0"
}
}
Loading

0 comments on commit 638bb64

Please sign in to comment.