feat: add inline-schema/csv-loader/rollup for tsup/vite
This commit is contained in:
+46
-1
@@ -1,6 +1,6 @@
|
||||
# inline-schema/csv-loader
|
||||
|
||||
A rspack loader for CSV files that uses inline-schema for type validation.
|
||||
A rspack/rollup loader for CSV files that uses inline-schema for type validation.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -24,6 +24,8 @@ Alice,30,true,[90; 85; 95]
|
||||
Bob,25,false,[75; 80; 70]
|
||||
```
|
||||
|
||||
## rspack/webpack
|
||||
|
||||
### rspack.config.js
|
||||
|
||||
```javascript
|
||||
@@ -52,6 +54,47 @@ module.exports = {
|
||||
};
|
||||
```
|
||||
|
||||
## Vite
|
||||
|
||||
### vite.config.ts
|
||||
|
||||
```typescript
|
||||
import { defineConfig } from 'vite';
|
||||
import { csvLoader } from 'inline-schema/csv-loader/rollup';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
csvLoader({
|
||||
delimiter: ',',
|
||||
quote: '"',
|
||||
escape: '\\',
|
||||
bom: true,
|
||||
comment: '#',
|
||||
trim: true,
|
||||
// emitTypes: false,
|
||||
// typesOutputDir: 'types',
|
||||
// writeToDisk: true,
|
||||
}),
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
## Tsup
|
||||
|
||||
### tsup.config.ts
|
||||
|
||||
```typescript
|
||||
import { defineConfig } from 'tsup';
|
||||
import { csvLoader } from 'inline-schema/csv-loader/rollup';
|
||||
|
||||
export default defineConfig({
|
||||
entry: ['src/index.ts'],
|
||||
format: ['cjs', 'esm'],
|
||||
dts: true,
|
||||
plugins: [csvLoader()],
|
||||
});
|
||||
```
|
||||
|
||||
### Generated TypeScript Types
|
||||
|
||||
当 `emitTypes: true` 时,loader 会自动生成 `.d.ts` 类型定义文件:
|
||||
@@ -91,6 +134,8 @@ import data from './data.csv';
|
||||
| `emitTypes` | boolean | `true` | Generate TypeScript declaration file (.d.ts) |
|
||||
| `typesOutputDir` | string | `''` | Output directory for generated type files (relative to output path) |
|
||||
| `writeToDisk` | boolean | `false` | Write .d.ts files directly to disk (useful for dev server) |
|
||||
| `include` | RegExp \| string \| Array | `/\.csv$/` | Include pattern for CSV files (Rollup only) |
|
||||
| `exclude` | RegExp \| string \| Array | - | Exclude pattern for CSV files (Rollup only) |
|
||||
|
||||
## Schema Syntax
|
||||
|
||||
|
||||
Reference in New Issue
Block a user