- node v16.14.2
To be able to use private Github Packages:
NOTE: it is already done for our prometheon/bedrock-fabric repo, so only required for other repos.
- Go to Developer Settings - Tokens
- Create a token with a scope:
read:packages
- Copy your token
Setup for npm:
npm config set @prometheon:registry https://npm.pkg.github.com npm login --registry=https://npm.pkg.github.com # use your token as password
Setup for yarn: yarn documentation
yarn add @prometheon/static-data
Use text data:
import cars from 'static-data/cars' // (See «preview» paragraph)
const makes = Object.keys(cars) // => [ 'Acura', 'Tesla', ... }
const models = Object.keys(cars['Tesla']) // => [ 'Model S', 'Model X', ... ]
const years = cars['Tesla']['Models S'].years // => [2012, 2013, 2014, ...]
const logo = cars['Tesla']['Model S'].logo // => 'tesla.png'
Use logos (works with NextJS):
const img = require(`static-data/cars/logos/${logo}`).default
console.log(img.src) // => '/_next/static/.../64fa.png'
...
<img src={img.src} width={img.width} height={img.height} />
Dynamic ES6 import might also work but more tricky as it requires either async function or top-level await.
{
make1_name: {
model1_name: {
years: [1994, 1995, 1996],
type: ['SUV'],
logo: 'image.png'
},
},
make2_name: {
model1_name: {
years: [2001, 2002],
type: ['Sedan'],
},
model2_name: {
years: [2022],
type: ['Pickup'],
},
},
};
To update data:
yarn build
Extend data yourself by editing additions.json
. It is automatically merged into index.json
at build step.