-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c220370
Showing
10 changed files
with
6,427 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: github-actions | ||
directory: / | ||
schedule: | ||
interval: weekly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: 'Release' | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.GH_REPO_TOKEN }} | ||
|
||
- name: 'Get yarn cache folder' | ||
id: yarn-cache | ||
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT | ||
|
||
- name: 'Handle yarn cache' | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.yarn-cache.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- run: yarn install | ||
|
||
- run: npx semantic-release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_REPO_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.idea/ | ||
.vscode/ | ||
lib/ | ||
node_modules/ | ||
|
||
.DS_Store | ||
.yarn/* | ||
!.yarn/releases | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/sdks | ||
!.yarn/versions |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
nodeLinker: node-modules | ||
yarnPath: .yarn/releases/yarn-3.3.0.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# vite-plugin-custom-tsconfig | ||
|
||
[![NPM](https://img.shields.io/npm/v/vite-plugin-custom-tsconfig?style=for-the-badge)](https://www.npmjs.com/package/vite-plugin-custom-tsconfig/) | ||
|
||
A very simple plugin to support using filenames like tsconfig.build.json or tsconfig.app.json with Vite. It copies your tsconfig.*.json to tsconfig.json before Vite starts, and removes it when the build is finished. | ||
|
||
## Installation | ||
|
||
**Using Yarn** | ||
|
||
```bash | ||
yarn add -D vite-plugin-custom-tsconfig | ||
``` | ||
|
||
**Using pnpm** | ||
|
||
```bash | ||
pnpm add -D vite-plugin-custom-tsconfig | ||
``` | ||
|
||
**Using npm** | ||
|
||
```bash | ||
npm install --save-dev vite-plugin-custom-tsconfig | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
// vite.config.ts | ||
import customTsConfig from 'vite-plugin-custom-tsconfig'; | ||
import {defineConfig} from 'vite'; | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
customTsConfig({ | ||
// default: 'tsconfig.build.json' | ||
filename: 'tsconfig.app.json', | ||
}), | ||
], | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "vite-plugin-custom-tsconfig", | ||
"version": "0.0.0-development", | ||
"repository": "github:edielemoine/vite-plugin-custom-tsconfig", | ||
"license": "MIT", | ||
"author": "Edie Lemoine <edie.lemoine@gmail.com>", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./lib/index.d.ts", | ||
"require": "./lib/index.cjs", | ||
"import": "./lib/index.js" | ||
} | ||
}, | ||
"main": "lib/index.cjs", | ||
"module": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib" | ||
], | ||
"release": { | ||
"branches": [ | ||
"main" | ||
] | ||
}, | ||
"scripts": { | ||
"build": "tsup src/index.ts --dts --out-dir lib --format esm,cjs --target node14", | ||
"prepare": "is-ci || husky install", | ||
"semantic-release": "semantic-release" | ||
}, | ||
"lint-staged": { | ||
"*.ts": "prettier --write", | ||
"package.json": "npx -q sort-package-json" | ||
}, | ||
"devDependencies": { | ||
"@tsconfig/node16": "^1.0.3", | ||
"@types/node": "^18.11.9", | ||
"husky": "^8.0.2", | ||
"is-ci": "^3.0.1", | ||
"lint-staged": "^13.0.3", | ||
"prettier": "^2.7.1", | ||
"semantic-release": "^19.0.5", | ||
"tsup": "^6.5.0", | ||
"typescript": "^4.9.3", | ||
"vite": "^3.2.4" | ||
}, | ||
"packageManager": "yarn@3.3.0", | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Plugin } from "vite"; | ||
import fs from "fs"; | ||
|
||
export interface PluginOptions { | ||
tsConfigPath?: string; | ||
} | ||
|
||
const NAME = "vite-plugin-custom-tsconfig"; | ||
const TSCONFIG_PATH = "tsconfig.json"; | ||
const BANNER = `// GENERATED BY ${NAME} \n`; | ||
|
||
const tsConfigExists = () => { | ||
return fs.existsSync(TSCONFIG_PATH); | ||
}; | ||
|
||
const tsConfigHasBanner = () => { | ||
const tsconfigContent = fs.readFileSync(TSCONFIG_PATH, "utf8"); | ||
|
||
return tsconfigContent.startsWith(BANNER); | ||
}; | ||
|
||
function customTsConfigPlugin(options?: PluginOptions): Plugin { | ||
const resolvedOptions: Required<PluginOptions> = { | ||
tsConfigPath: "tsconfig.build.json", | ||
...options, | ||
}; | ||
|
||
return { | ||
name: NAME, | ||
|
||
config() { | ||
if (tsConfigExists() && tsConfigHasBanner()) { | ||
throw new Error( | ||
"tsconfig.json already exists. Please delete it or remove vite-plugin-custom-tsconfig from your Vite config" | ||
); | ||
} | ||
|
||
const customTsConfigContent = fs.readFileSync( | ||
resolvedOptions.tsConfigPath, | ||
"utf8" | ||
); | ||
|
||
fs.writeFileSync(TSCONFIG_PATH, BANNER + customTsConfigContent); | ||
}, | ||
|
||
closeBundle() { | ||
if (!tsConfigExists()) { | ||
return; | ||
} | ||
|
||
if (!tsConfigHasBanner()) { | ||
throw new Error( | ||
"tsconfig.json does not contain the expected banner. Please delete it or remove vite-plugin-custom-tsconfig from your Vite config" | ||
); | ||
} | ||
|
||
fs.rmSync("tsconfig.json", { force: true }); | ||
}, | ||
}; | ||
} | ||
|
||
export default customTsConfigPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "@tsconfig/node16/tsconfig.json", | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"target": "esnext", | ||
"moduleResolution": "node", | ||
"sourceMap": true | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
Oops, something went wrong.