Skip to content

Commit

Permalink
feat(break-change)!: deprecate effects option. support absolute inp…
Browse files Browse the repository at this point in the history
…utDir and cacheDir
  • Loading branch information
hemengke1997 committed May 25, 2024
1 parent 17cc51f commit f43b05e
Show file tree
Hide file tree
Showing 30 changed files with 3,250 additions and 2,354 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# vite-plugin-public-typescript

**English** | [中文](./README-zh.md)
**English** | [中文](./README.zh.md)

> A vite plugin inject typescript script into html
Expand Down Expand Up @@ -61,17 +61,16 @@ pnpm add vite-plugin-public-typescript -D

| Option | Type | Default | Description |
| ---------------- | -------------------------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------- |
| `inputDir` | `string` | `public-typescript` | The directory where the `typescript` is stored |
| `outputDir` | `string` | `public-typescript` | The directory where the `javascript` is stored |
| `inputDir` | `string` | `public-typescript` | Directory of input typescript files |
| `publicDir` | `string` | publicDir of vite's config | Vite's publicDir |
| `outputDir` | `string` | '' | Directory of output javascript files after building |
| `esbuildOptions` | `BuildOptions` | `{}` | esbuild build options |
| `babel` | `boolean | ESBuildPluginBabelOptions` | `false` | babel compilation (if you need to be compatible with browsers below es6, please turn it on) |
| `manifestName` | `string` | `manifest` | The name of the `manifest` file |
| `hash` | `boolean` | `true` | Whether the compiled `js` generates `hash` |
| `esbuildOptions` | `BuildOptions` | `{}` | esbuild build options |
| `sideEffects` | `boolean` | `true` | Whether to compile third-party libraries |
| `destination` | `string` | `memory` | Output mode: memory mode \| file mode |
| `cacheDir` | `string` | `node_modules/.vite-plugin-public-typescript` | The directory where the `manifest` cache is stored |
| `base` | `string` | vite config `base` | Resource base url |
| `publicDir` | `string` | vite config `publicDir` | public directory |
| `babel` | `boolean | ESBuildPluginBabelOptions` | `false` | babel compilation (if you need to be compatible with browsers below es6, please turn it on) |

## Usage

Expand Down
25 changes: 12 additions & 13 deletions README-zh.md → README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,18 @@ pnpm add vite-plugin-public-typescript -D

## 配置项

| 参数 | 类型 | 默认值 | 描述 |
| --------------- | -------------------------------------- | --------------------------------------------- | ---------------------------------------------- |
| inputDir | `string` | `public-typescript` | 存放需要编译的 `typescript` 的目录 |
| outputDir | `string` | `/` | 输出公共 javascript 的目录,相对于 `publicDir` |
| manifestName | `string` | `manifest` | `manifest` 的文件名 |
| hash | `boolean` | `true` | 编译后的 `js` 是否生成 `hash ` |
| esbuildOptions | `BuildOptions` | `{}` | esbuild 构建选项 |
| ~~sideEffects~~ | `boolean` | `true` | 是否编译三方库(v2.0.0废弃⚠️) |
| destination | `string` | `memory` | 输出模式:内存模式 \| 文件模式 |
| cacheDir | `string` | `node_modules/.vite-plugin-public-typescript` | 存放manifest缓存的目录 |
| base | `string` | vite config 中的 `base` | 资源 base url |
| publicDir | `string` | vite config 中的 `publicDir` | public目录 |
| babel | `boolean | ESBuildPluginBabelOptions` | `false` | babel编译(如果需要兼容es6以下浏览器,请开启) |
| 参数 | 类型 | 默认值 | 描述 |
| -------------- | -------------------------------------- | --------------------------------------------- | ---------------------------------------------- |
| inputDir | `string` | `public-typescript` | 存放需要编译的 `typescript` 的目录 |
| publicDir | `string` | vite config 中的 publicDir | public 目录 |
| outputDir | `string` | `/` | 输出公共 javascript 的目录,相对于 `publicDir` |
| esbuildOptions | `BuildOptions` | `{}` | esbuild 构建选项 |
| babel | `boolean | ESBuildPluginBabelOptions` | `false` | babel编译(如果需要兼容es6以下浏览器,请开启) |
| manifestName | `string` | `manifest` | `manifest` 的文件名 |
| hash | `boolean` | `true` | 编译后的 `js` 是否生成 `hash` |
| destination | `string` | `memory` | 输出模式:内存模式 \| 文件模式 |
| cacheDir | `string` | `node_modules/.vite-plugin-public-typescript` | 存放manifest缓存的目录 |
| base | `string` | vite config 中的 `base` | 资源 base url |



Expand Down
3 changes: 0 additions & 3 deletions commitlint.config.cjs

This file was deleted.

8 changes: 1 addition & 7 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,4 @@ import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)

const { defineConfig } = require('@minko-fe/eslint-config')
export default defineConfig([
{
rules: {
'import/no-mutable-exports': 'off',
},
},
])
export default defineConfig([])
82 changes: 0 additions & 82 deletions migration-v2.0.0.md

This file was deleted.

72 changes: 41 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"files": [
"*.d.ts",
"README.md",
"dist",
"package.json"
"dist"
],
"main": "./dist/node/index.cjs",
"module": "./dist/node/index.js",
Expand All @@ -42,66 +41,72 @@
"./*": "./*"
},
"scripts": {
"dev": "simple-git-hooks && tsup --watch",
"dev": "tsup --watch",
"build": "rm -rf dist && tsup",
"build:pages": "pnpm run build && cd playground/spa && pnpm run build",
"prepare": "simple-git-hooks",
"test": "run-s test:unit test:serve test:build",
"test:unit": "vitest run",
"test:serve": "vitest run -c vitest.config.e2e.ts",
"test:build": "cross-env VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
"commitlint": "commitlint -e",
"lint": "eslint . --fix",
"up": "pnpm update --i --L",
"taze": "taze -I -w",
"up": "taze -I -w",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"bump": "bumpp package.json -c --no-push -t --all -x \"pnpm run changelog\""
},
"peerDependencies": {
"esbuild": ">=0.19.0",
"vite": ">=4.0.0 || >=5.0.0"
},
"peerDependenciesMeta": {
"esbuild": {
"optional": true
}
},
"dependencies": {
"@antfu/install-pkg": "^0.1.1",
"@babel/core": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"@babel/preset-typescript": "^7.23.3",
"browserslist": "^4.22.3",
"core-js": "^3.35.1",
"@antfu/install-pkg": "^0.3.3",
"@babel/core": "^7.24.5",
"@babel/preset-env": "^7.24.5",
"@babel/preset-typescript": "^7.24.1",
"browserslist": "^4.23.0",
"core-js": "^3.37.1",
"debug": "^4.3.4",
"esbuild": "^0.19.12",
"esbuild-plugin-browserslist": "^0.10.0",
"esbuild": "^0.21.3",
"esbuild-plugin-browserslist": "^0.12.0",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"local-pkg": "^0.5.0",
"magic-string": "^0.30.7",
"on-change": "^4.0.2",
"magic-string": "^0.30.10",
"on-change": "^5.0.1",
"parse5": "^7.1.2",
"picocolors": "^1.0.0",
"picocolors": "^1.0.1",
"prompts": "^2.4.2",
"std-env": "^3.7.0",
"watcher": "^2.3.0"
"watcher": "^2.3.1"
},
"devDependencies": {
"@commitlint/cli": "^18.6.0",
"@commitlint/cli": "^19.3.0",
"@minko-fe/commitlint-config": "^2.0.7",
"@minko-fe/eslint-config": "^2.1.2",
"@minko-fe/tsconfig": "^2.0.7",
"@minko-fe/eslint-config": "^3.2.0",
"@minko-fe/tsconfig": "^2.1.0",
"@types/babel__core": "^7.20.5",
"@types/babel__preset-env": "^7.9.6",
"@types/debug": "^4.1.12",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.11.16",
"@types/node": "^20.12.12",
"@types/prompts": "^2.4.9",
"bumpp": "^9.3.0",
"conventional-changelog-cli": "^4.1.0",
"bumpp": "^9.4.1",
"conventional-changelog-cli": "^5.0.0",
"cross-env": "^7.0.3",
"eslint": "^8.56.0",
"npm-run-all2": "^6.1.2",
"simple-git-hooks": "^2.9.0",
"taze": "^0.12.3",
"tsup": "^6.7.0",
"typescript": "^5.3.3",
"vite": "^5.0.12",
"vitest": "^0.34.6",
"eslint": "^8.57.0",
"npm-run-all2": "^6.2.0",
"simple-git-hooks": "^2.11.1",
"taze": "^0.13.8",
"tsup": "^8.0.2",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vitest": "^1.6.0",
"vitest-e2e": "^0.0.10"
},
"engines": {
Expand All @@ -110,5 +115,10 @@
"simple-git-hooks": {
"commit-msg": "npm run commitlint",
"pre-commit": "npm run lint"
},
"commitlint": {
"extends": [
"@minko-fe/commitlint-config"
]
}
}
1 change: 0 additions & 1 deletion playground/spa-file-mode/public/out/env.98fe7b3e.js

This file was deleted.

1 change: 1 addition & 0 deletions playground/spa-file-mode/public/out/env.9aa2ccba.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(function(){var e={VITE_ENV_FROM_ENVFILE:"imfromdotenv",BASE_URL:"/vite-plugin-public-typescript/",MODE:"production",DEV:!1,PROD:!0,SSR:!1};window.VITE_ENV=e;})();
5 changes: 2 additions & 3 deletions playground/spa-file-mode/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import { injectScripts, publicTypescript } from 'vite-plugin-public-typescript'

process.env.__Manifest_Path__ = __dirname

// https://vitejs.dev/config/
export default defineConfig(() => ({
base: '/vite-plugin-public-typescript/',
Expand All @@ -15,9 +17,6 @@ export default defineConfig(() => ({
plugins: [
react(),
publicTypescript({
inputDir: 'public-typescript',
manifestName: 'manifest',
hash: true,
outputDir: 'out',
destination: 'file',
babel: true,
Expand Down
10 changes: 3 additions & 7 deletions playground/spa/__tests__/spa.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ function manifestLike() {
describe('manifest', () => {
let manifest: string
beforeAll(() => {
try {
manifest = readFile(manifestPath)
} catch {}
manifest = readFile(manifestPath)
})

test('should generate manifest', () => {
Expand All @@ -76,10 +74,8 @@ describe.skipIf(isServe)('build', () => {
let jsFiles: string[]
let manifest: string
beforeAll(() => {
try {
manifest = readFile(manifestPath)
jsFiles = listFiles('dist/out')
} catch {}
manifest = readFile(manifestPath)
jsFiles = listFiles('dist/out')
})

test('should generate js assetes after build', () => {
Expand Down
6 changes: 2 additions & 4 deletions playground/spa/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import { injectScripts, publicTypescript } from 'vite-plugin-public-typescript'

process.env.__Manifest_Path__ = __dirname

// https://vitejs.dev/config/
export default defineConfig(() => ({
base: '/vite-plugin-public-typescript/',
Expand All @@ -16,12 +18,8 @@ export default defineConfig(() => ({
plugins: [
react(),
publicTypescript({
inputDir: 'public-typescript',
manifestName: 'manifest',
hash: true,
outputDir: 'out',
destination: 'memory',
cacheDir: 'node_modules/.vite-plugin-public-typescript',
babel: true,
}),
injectScripts((manifest) => [
Expand Down
2 changes: 2 additions & 0 deletions playground/ssr/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import { publicTypescript } from 'vite-plugin-public-typescript'

process.env.__Manifest_Path__ = __dirname

export default defineConfig({
plugins: [react(), publicTypescript({ babel: true })],
build: {
Expand Down
Loading

0 comments on commit f43b05e

Please sign in to comment.