i have a csv file in this structure
name,year,href,src
Parasite,2019,parasite-2019,film-poster/4/2/6/4/0/6/426406-parasite-0-460-0-690-crop.jpg
i would like to import this file as a list with each line as a dict in this way:
[{'name':'Parasite','year':'2019','href':'parasite-2019','src':'film-poster/4/2/6/4/0/6/426406-parasite-0-460-0-690-crop.jpg'}]
i tried using import csv from './filmList.csv'
inside the <script>
tag, but that only gives me an error on load:
[plugin:vite:import-analysis] Failed to parse source for import analysis because the content contains invalid JS syntax. You may need to install appropriate plugins to handle the .csv file format.
CodePudding user response:
Install @rollup/plugin-dsv
as a dev dependency:
npm i -D @rollup/plugin-dsv
...and configure Vite to use it:
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import dsv from '@rollup/plugin-dsv'