Skip to content
Merged

Dev #84

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 54 additions & 16 deletions docs/en/plugins/vite-plugin-combine/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,94 @@
## TypeScript Definitions

```typescript
import type { NullValue } from 'rollup';
import type { ConfigEnv, UserConfig } from 'vite';
import type { PluginOptions as DtsPluginOptions } from 'vite-plugin-dts';
import type { LogLevel } from 'vp-runtime-helper';

export type { LogLevel };

export type NameExport = (name: string, filePath: string) => string;

export interface Options {
/**
* Path to the files to be combined, supports glob patterns.
*
* 需要合并的文件路径,支持 glob 模式。
*/
src: string | string[];

/**
* Path to the target file after combination.
*
* 合并后的目标文件虚拟路径。
*
* @default 'index.js'
*/
target: string;

/**
* Whether to overwrite the existing target file.
* @default false
*/
overwrite?: boolean;

/**
* Custom function or boolean value for controlling export name generation.
* Custom function or boolean value for controlling the generation of export names.
*
* 自定义导出名称的函数或布尔值,用于控制导出名称的生成方式。
*/
nameExport?: NameExport | boolean;

/**
* Exported module types.
*
* 导出的模块类型
*
* @default 'named'
*/
exports?: 'named' | 'default' | 'both' | 'none';
exports?: 'named' | 'default' | 'both' | 'all' | 'none';

/**
* Plugin execution order. 'pre' runs before others, 'post' after.
* @see [Vite Plugin Ordering](https://cn.vitejs.dev/guide/api-plugin.html#plugin-ordering)
* The value of enforce can be either `"pre"` or `"post"`, see more at https://vitejs.dev/guide/api-plugin.html#plugin-ordering.
*
* 强制执行顺序,`pre` 前,`post` 后,参考 https://cn.vitejs.dev/guide/api-plugin.html#plugin-ordering。
*/
enforce?: 'pre' | 'post';

/**
* Logging level configuration.
* Apply the plugin only for serve or build, or on certain conditions.
*
* 应用插件仅在 serve 或 build 时,或满足某些条件的情况下。
*/
logLevel?: LogLevel;
apply?: 'serve' | 'build' | ((this: void, config: UserConfig, env: ConfigEnv) => boolean);

/**
* Current working directory.
* Current Working Directory.
*
* 当前工作目录
*/
cwd?: string;

/**
* Process code before writing to the file.
* Log level
*
* 输出日志等级
*/
logLevel?: LogLevel;

/**
* Handle code before writing to the file.
*
* 写入文件前处理代码字符串
*/
beforeWrite?: (code: string) => string | NullValue;

/**
* Whether to output the banner
*
* 是否输出 banner
*/
enableBanner?: boolean;

/**
* Whether to generate d.ts file
*
* 是否生成 d.ts 文件
*/
beforeWrite?: (code: string) => string | void | undefined | null;
dts?: boolean | DtsPluginOptions;
}
```
2 changes: 1 addition & 1 deletion docs/en/plugins/vite-plugin-combine/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default defineConfig({
This will generate the following files:

`dist/index.mjs`
```mjs
```js
export { default as default2 } from './Button';
export { default as default3 } from './Input';
export { default as default4 } from './Select';
Expand Down
49 changes: 34 additions & 15 deletions docs/zh/plugins/vite-plugin-combine/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
## TypeScript 定义

```ts
import type { NullValue } from 'rollup';
import type { ConfigEnv, UserConfig } from 'vite';
import type { PluginOptions as DtsPluginOptions } from 'vite-plugin-dts';
import type { LogLevel } from 'vp-runtime-helper';

export type { LogLevel };

export type NameExport = (name: string, filePath: string) => string;

export interface Options {
Expand All @@ -15,21 +22,12 @@ export interface Options {
/**
* Path to the target file after combination.
*
* 合并后的目标文件路径
* 合并后的目标文件虚拟路径
*
* @default 'index.js'
*/
target: string;

/**
* Whether to overwrite the existing target file。
*
* 是否覆盖已存在的目标文件。
*
* @default false
*/
overwrite?: boolean;

/**
* Custom function or boolean value for controlling the generation of export names.
*
Expand All @@ -44,7 +42,7 @@ export interface Options {
*
* @default 'named'
*/
exports?: 'named' | 'default' | 'both' | 'none';
exports?: 'named' | 'default' | 'both' | 'all' | 'none';

/**
* The value of enforce can be either `"pre"` or `"post"`, see more at https://vitejs.dev/guide/api-plugin.html#plugin-ordering.
Expand All @@ -54,11 +52,11 @@ export interface Options {
enforce?: 'pre' | 'post';

/**
* Log level
* Apply the plugin only for serve or build, or on certain conditions.
*
* 输出日志等级
* 应用插件仅在 serve 或 build 时,或满足某些条件的情况下。
*/
logLevel?: LogLevel;
apply?: 'serve' | 'build' | ((this: void, config: UserConfig, env: ConfigEnv) => boolean);

/**
* Current Working Directory.
Expand All @@ -67,11 +65,32 @@ export interface Options {
*/
cwd?: string;

/**
* Log level
*
* 输出日志等级
*/
logLevel?: LogLevel;

/**
* Handle code before writing to the file.
*
* 写入文件前处理代码字符串
*/
beforeWrite?: (code: string) => string | void | undefined | null;
beforeWrite?: (code: string) => string | NullValue;

/**
* Whether to output the banner
*
* 是否输出 banner
*/
enableBanner?: boolean;

/**
* Whether to generate d.ts file
*
* 是否生成 d.ts 文件
*/
dts?: boolean | DtsPluginOptions;
}
```
2 changes: 1 addition & 1 deletion docs/zh/plugins/vite-plugin-combine/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default defineConfig({
输出的文件内容:

`dist/index.mjs`
```mjs
```js
export { default as default2 } from './Button';
export { default as default3 } from './Input';
export { default as default4 } from './Select';
Expand Down
14 changes: 4 additions & 10 deletions examples/config/vite.combine.1.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineConfig, Plugin } from 'vite';
import { defineConfig, PluginOption } from 'vite';
import vitePluginCombine from 'vite-plugin-combine';
import ts from 'vite-plugin-dts';

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -9,14 +8,9 @@ export default defineConfig({
logLevel: 'TRACE',
src: ['src/util/*.ts', '!src/util/typings.ts'],
target: 'src/combine.1.ts',
nameExport: true
}),
ts({
tsconfigPath: './tsconfig.build.json',
compilerOptions: {
declarationDir: 'dist/combine/1'
}
}) as unknown as Plugin
nameExport: true,
dts: true
}) as unknown as PluginOption
],
build: {
outDir: 'dist/combine/1',
Expand Down
14 changes: 4 additions & 10 deletions examples/config/vite.combine.2.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineConfig, Plugin } from 'vite';
import { defineConfig, PluginOption } from 'vite';
import vitePluginCombine from 'vite-plugin-combine';
import ts from 'vite-plugin-dts';

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -9,14 +8,9 @@ export default defineConfig({
logLevel: 'TRACE',
src: ['src/util/*.ts', '!src/util/typings.ts'],
target: 'src/combine.2.ts',
exports: 'default'
}),
ts({
tsconfigPath: './tsconfig.build.json',
compilerOptions: {
declarationDir: 'dist/combine/2'
}
}) as Plugin
exports: 'default',
dts: true
}) as unknown as PluginOption
],
build: {
outDir: 'dist/combine/2',
Expand Down
14 changes: 4 additions & 10 deletions examples/config/vite.combine.3.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineConfig, Plugin } from 'vite';
import { defineConfig, PluginOption } from 'vite';
import vitePluginCombine from 'vite-plugin-combine';
import ts from 'vite-plugin-dts';

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -9,14 +8,9 @@ export default defineConfig({
logLevel: 'TRACE',
src: ['src/util/*.ts', '!src/util/typings.ts'],
target: 'src/combine.3.ts',
exports: 'both'
}),
ts({
tsconfigPath: './tsconfig.build.json',
compilerOptions: {
declarationDir: 'dist/combine/3'
}
}) as Plugin
exports: 'both',
dts: true
}) as unknown as PluginOption
],
build: {
outDir: 'dist/combine/3',
Expand Down
14 changes: 4 additions & 10 deletions examples/config/vite.combine.4.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineConfig, Plugin } from 'vite';
import { defineConfig, PluginOption } from 'vite';
import vitePluginCombine from 'vite-plugin-combine';
import ts from 'vite-plugin-dts';

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -9,14 +8,9 @@ export default defineConfig({
logLevel: 'TRACE',
src: ['src/util/*.ts', '!src/util/typings.ts'],
target: 'src/combine.4.ts',
nameExport: (name) => `my${name}`
}),
ts({
tsconfigPath: './tsconfig.build.json',
compilerOptions: {
declarationDir: 'dist/combine/4'
}
}) as Plugin
nameExport: (name) => `my${name}`,
dts: true
}) as unknown as PluginOption
],
build: {
outDir: 'dist/combine/4',
Expand Down
14 changes: 4 additions & 10 deletions examples/config/vite.combine.5.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import { defineConfig, Plugin } from 'vite';
import { defineConfig, PluginOption } from 'vite';
import vitePluginCombine from 'vite-plugin-combine';
import ts from 'vite-plugin-dts';

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -12,14 +11,9 @@ export default defineConfig({
target: 'src/combine.5.ts',
beforeWrite(code) {
return `${code}export * from './util/typings';`;
}
}),
ts({
tsconfigPath: './tsconfig.build.json',
compilerOptions: {
declarationDir: 'dist/combine/5'
}
}) as Plugin
},
dts: true
}) as unknown as PluginOption
],
build: {
outDir: 'dist/combine/5',
Expand Down
14 changes: 4 additions & 10 deletions examples/config/vite.combine.6.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineConfig, Plugin } from 'vite';
import { defineConfig, PluginOption } from 'vite';
import vitePluginCombine from 'vite-plugin-combine';
import ts from 'vite-plugin-dts';

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -9,14 +8,9 @@ export default defineConfig({
logLevel: 'TRACE',
src: ['src/util/*.ts', '!src/util/typings.ts'],
target: 'src/combine.6.ts',
exports: 'none'
}),
ts({
tsconfigPath: './tsconfig.build.json',
compilerOptions: {
declarationDir: 'dist/combine/6'
}
}) as Plugin
exports: 'none',
dts: true
}) as unknown as PluginOption
],
build: {
outDir: 'dist/combine/6',
Expand Down
1 change: 0 additions & 1 deletion examples/vite3-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"vite": "^3.1.0",
"vite-plugin-combine": "workspace:^",
"vite-plugin-cp": "workspace:^",
"vite-plugin-dts": "^4.5.3",
"vite-plugin-external": "workspace:^",
"vite-plugin-hook-use": "workspace:^",
"vite-plugin-include-css": "workspace:^",
Expand Down
1 change: 0 additions & 1 deletion examples/vite4-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"vite": "^4.5.0",
"vite-plugin-combine": "workspace:^",
"vite-plugin-cp": "workspace:^",
"vite-plugin-dts": "^4.5.3",
"vite-plugin-external": "workspace:^",
"vite-plugin-hook-use": "workspace:^",
"vite-plugin-include-css": "workspace:^",
Expand Down
Loading