How to use the parcel-bundler.Packager function in parcel-bundler

To help you get started, we’ve selected a few parcel-bundler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dobesv / parcel-plugin-assets-list / UrlsPackager.js View on Github external
const Packager = require('parcel-bundler').Packager;

class UrlsPackager extends Packager {

    addAsset(asset) {
        return this.write(asset.generated.urls);
    }

}

module.exports = UrlsPackager;
github dobesv / parcel-plugin-assets-list / JSONPackager.js View on Github external
const Packager = require('parcel-bundler').Packager;

class JSONPackager extends Packager {
    constructor(...args) {
        super(...args);
        this.combinedAst = {};
    }

    addAsset(asset) {
        if(!asset.generated.json)
            throw new Error(`JSON missing in parsed asset: ${asset.relativeName}; got ${Object.keys(asset.generated).join(',')}`);
        try {
            Object.assign(this.combinedAst, JSON.parse(asset.generated.json));
        } catch (e) {
            e.message = `In ${asset.name}: ${e.message}:\n${asset.generated.json}`;
            throw e;
        }