To create an npm package, that
data
that is an array of JS objects e.g.const export data = [{a:1, b:2}, {a:3, b:4}];
I have a working Node implementation, which builds with Parcel. It packages a data file (.csv) and an index.js which reads (using d3) and parses (using fs) the csv at runtime to a constant variable data
. This works fine in Node.
The bundled version fails, because of the reliance on fs
, which is Node-only. So I would like to know:
fs
which is browser-friendly (I couldn't figure this out);Instead of putting the CSV in a .csv
file, you can export a string from another JS file, e.g. data.js
:
export default `[paste csv here]`
Then simply import it and use that file:
import csv from "./data"
This is nice because after bundling the CSV is in the same file, but it doesn't clutter your code.
Alternatively, I found an npm package that's a parcel plugin that just might do it for you: https://www.npmjs.com/package/parcel-transformer-csv