DSV transformer for Rollup and Vite using d3-dsv.
This is a pure ESM module with no CommonJS build. You must set
"type": "module"
in yourpackage.json
to use this plugin.
-
Install by running
yarn add --dev michigandaily/rollup-plugin-dsv
. -
Depending on whether you are using Rollup or Vite, add the plugin to your configuration:
-
In Rollup, import the plugin like the following:
// rollup.config.js import dsv from '@michigandaily/rollup-plugin-dsv'; export default { plugins: [dsv()] };
-
In Vite, import the plugin like the following:
// vite.config.js import { defineConfig } from "vite"; import dsv from "@michigandaily/rollup-plugin-dsv"; export default defineConfig({ plugins: [dsv()], });
-
-
You can optionally add an
include
orexclude
argument to the plugin in the configuration to specify which files you want to run the transformer on:dsv({include: ["**.csv", "**.tsv", "**.dsv"]})
Now, you can import a CSV file like so:
import data from "../data.csv"
You can also import a TSV file:
import data from "../data.tsv"
If you have a file with a different type of delimiter, you can import it with a delimiter
query parameter. Consider a file with values delimited with colons. You can import it like so:
import data from "../data.dsv?delimiter=:"
By default, this transformer will use d3.autoType
to infer data types. If you want to disable automatic typing, import with a autoType=false
query parameter:
import data from "../data.csv?autoType=false"
When typing, dates will not be converted to Date objects, they will remain as a string.
If you want to only retrieve certain columns of values from a DSV, use the columns
query paramter. The following import will only import the a
and b
columns from a CSV file:
import data from "../data.csv?columns=a,b"