Expands upon the functionality of parcel-plugin-json-url-loader:
// imports JSON object
import { data as foo } from 'path/to/file.json';
// imports file URL
import { url as bar } from 'path/to/file.json';
(The remainder of this README is unmodified except for codeblocks)
Lots of users inculding me are suffered from the build-in feature of parcel
which bundles json
file as strings into the final bundler by default parcel-bundler#501. When people are looking for the official solutions, parcel
is still waiting for the solution from react community devongovett@parcel-bundler#501. As a matter of fact, it's something easy to hanle with parcel
's plugin system. So I made this.
yarn add --dev parcel-plugin-json-extended
or
npm install --save-dev parcel-plugin-json-extended
There is no options for you to think of. Just install it and checkout the output:
const asset = require('path/to/json/file.json');
console.log(asset.url); // /file.3a855491.json
console.log(asset.data); // { json object... }
There are no tests yet, no linters, no production grade garrentee, and works simply as possible. Any feature requests or bugfixes are welcome.