Export Image
Export Code
package.json
{
"dependencies": {
"d3": "6.7.0",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"vizhub": {
"libraries": {
"d3": {
"global": "d3",
"path": "/dist/d3.min.js"
},
"react": {
"global": "React",
"path": "/umd/react.production.min.js"
},
"react-dom": {
"global": "ReactDOM",
"path": "/umd/react-dom.production.min.js"
}
}
},
"license": "ISC"
}

Hello Package.json

Curran Kelleher

Sunday, May 4, 2025: 0 viewsMonday, May 5, 2025: 0 viewsTuesday, May 6, 2025: 0 viewsWednesday, May 7, 2025: 0 viewsThursday, May 8, 2025: 0 viewsFriday, May 9, 2025: 0 viewsSaturday, May 10, 2025: 0 viewsSunday, May 11, 2025: 0 viewsMonday, May 12, 2025: 0 viewsTuesday, May 13, 2025: 0 viewsWednesday, May 14, 2025: 0 viewsThursday, May 15, 2025: 0 viewsFriday, May 16, 2025: 0 viewsSaturday, May 17, 2025: 2 viewsSunday, May 18, 2025: 0 viewsMonday, May 19, 2025: 3 viewsTuesday, May 20, 2025: 0 viewsWednesday, May 21, 2025: 2 viewsThursday, May 22, 2025: 0 viewsFriday, May 23, 2025: 0 viewsSaturday, May 24, 2025: 0 viewsSunday, May 25, 2025: 1 viewMonday, May 26, 2025: 0 viewsTuesday, May 27, 2025: 0 viewsWednesday, May 28, 2025: 0 viewsThursday, May 29, 2025: 5 viewsFriday, May 30, 2025: 0 viewsSaturday, May 31, 2025: 0 viewsSunday, June 1, 2025: 0 viewsMonday, June 2, 2025: 2 viewsTuesday, June 3, 2025: 0 viewsWednesday, June 4, 2025: 2 viewsThursday, June 5, 2025: 0 viewsFriday, June 6, 2025: 3 viewsSaturday, June 7, 2025: 0 viewsSunday, June 8, 2025: 0 viewsMonday, June 9, 2025: 1 viewTuesday, June 10, 2025: 4 viewsWednesday, June 11, 2025: 0 viewsThursday, June 12, 2025: 2 viewsFriday, June 13, 2025: 1 viewSaturday, June 14, 2025: 0 viewsSunday, June 15, 2025: 0 viewsMonday, June 16, 2025: 7 viewsTuesday, June 17, 2025: 2 viewsWednesday, June 18, 2025: 3 viewsThursday, June 19, 2025: 0 viewsFriday, June 20, 2025: 5 viewsSaturday, June 21, 2025: 0 viewsSunday, June 22, 2025: 0 viewsMonday, June 23, 2025: 0 viewsTuesday, June 24, 2025: 4 viewsWednesday, June 25, 2025: 0 viewsThursday, June 26, 2025: 0 viewsFriday, June 27, 2025: 0 viewsSaturday, June 28, 2025: 2 viewsSunday, June 29, 2025: 0 viewsMonday, June 30, 2025: 0 viewsTuesday, July 1, 2025: 0 viewsWednesday, July 2, 2025: 0 viewsThursday, July 3, 2025: 0 viewsFriday, July 4, 2025: 0 viewsSaturday, July 5, 2025: 2 viewsSunday, July 6, 2025: 0 viewsMonday, July 7, 2025: 5 viewsTuesday, July 8, 2025: 0 viewsWednesday, July 9, 2025: 2 viewsThursday, July 10, 2025: 0 viewsFriday, July 11, 2025: 0 viewsSaturday, July 12, 2025: 1 viewSunday, July 13, 2025: 0 viewsMonday, July 14, 2025: 1 viewTuesday, July 15, 2025: 0 viewsWednesday, July 16, 2025: 0 viewsThursday, July 17, 2025: 2 viewsFriday, July 18, 2025: 0 viewsSaturday, July 19, 2025: 0 viewsSunday, July 20, 2025: 0 viewsMonday, July 21, 2025: 0 viewsTuesday, July 22, 2025: 0 viewsWednesday, July 23, 2025: 0 viewsThursday, July 24, 2025: 0 viewsFriday, July 25, 2025: 0 viewsSaturday, July 26, 2025: 0 viewsSunday, July 27, 2025: 2 viewsMonday, July 28, 2025: 2 viewsTuesday, July 29, 2025: 5 viewsWednesday, July 30, 2025: 3 viewsThursday, July 31, 2025: 0 views
222 views in last 90 days
Last edited Mar 21, 2025
Created on Dec 15, 2020
Forked from D3 Starter

An example of VizHub's package.json features.

Wait, what!?

That's right! You can now use package.json in VizHub. It's a way to declare your dependencies. If you use this, there's no longer any need to add any <script> tags yourself to index.html. VizHub will automatically append these when the page runs, based on the dependencies defined in package.json. To be clear, the dependencies are not included in the bundle. They are still pulled in from a CDN.

Because dependencies are pulled in from a CDN via <script> tags, and those tags introduce browser globals that define the packages, VizHub somehow needs to know how to resolve package names (like the 'react' part of import React from 'react') to browser globals (such as window.React). To date, this mapping has been defined in vizhub-libraries, which is a big list of mappings. This approach is not ideal, because if a library is not on that list, you can't use it with ES6 import syntax. But all that is about to change.

To support usage of any package with ES6 import syntax, we've added a special vizhub.libraries field in package.json. This field lets you define the mappings from package names to browser globals yourself. Also, since the CDN path to the browser build is sometimes not at the package root, and can be different for each package (and there's no way of knowing programmatically what it is), you can also specify what path to use.

You can also specify a custom license in the license field of package.json. This field is expected to be a valid SPDX license identifier, as described in the NPM Package.json documentation. If a license field is not present, the default MIT License is used.

Here's an example:

In the above example, the vizhub.libraries field specifies the global and path for react and react-dom. For React, the global tells VizHub to resolve the 'react' package to window.React, and the path field tells VizHub to append /umd/react-dom.production.min.js to the CDN path used in the <script> tag that pulls in the library. The CDN paths used are of the form https://unpkg.com/${name}@${version}${path}.

By the way, the above snippet is embedded using VizHub's snippet embed feature.

ISC Licensed