How to use the @parcel/plugin.Packager function in @parcel/plugin

To help you get started, we’ve selected a few @parcel/plugin 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 parcel-bundler / parcel / packages / packagers / js / src / JSPackager.js View on Github external
import {concat, link, generate} from '@parcel/scope-hoisting';
import SourceMap from '@parcel/source-map';
import {
  countLines,
  PromiseQueue,
  relativeBundlePath,
  replaceBundleReferences,
} from '@parcel/utils';
import path from 'path';

const PRELUDE = fs
  .readFileSync(path.join(__dirname, 'prelude.js'), 'utf8')
  .trim()
  .replace(/;$/, '');

export default new Packager({
  async package({
    bundle,
    bundleGraph,
    getInlineBundleContents,
    getSourceMapReference,
    options,
  }) {
    function replaceReferences({contents, map}) {
      return replaceBundleReferences({
        bundle,
        bundleGraph,
        contents,
        getInlineReplacement: (dependency, inlineType, content) => ({
          from: `"${dependency.id}"`,
          to: inlineType === 'string' ? JSON.stringify(content) : content,
        }),

@parcel/plugin

MIT
Latest version published 9 days ago

Package Health Score

89 / 100
Full package analysis

Popular @parcel/plugin functions

Similar packages