How to use the parcel-bundler.prototype 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 remoteinterview / zero / packages / parcel-bundler / index.js View on Github external
require("./applyMods")(); // apply our mods
// this is a wrapper around parcel, need to apply patches to parcel
var Bundler = require("parcel-bundler");
var localRequire = require("parcel-bundler/src/utils/localRequire");
const logger = require("@parcel/logger");
const pkg = require("./package");
const path = require("path");

// limit workers parcel can spawn to 0 by default
// we do this because we spawn a parcel process for each page
// and we don't want each of them to spawn their own 2 or so worker processes.
process.env.PARCEL_WORKERS = process.env.PARCEL_WORKERS || 0;

/// modify parcel to load plugins from zero's folder instead of user's package.json
Bundler.prototype.loadPlugins = async function() {
  let relative = path.dirname(
    path.join(require.resolve("parcel-bundler"), "..")
  );
  if (!pkg) {
    return;
  }

  try {
    let deps = Object.assign({}, pkg.dependencies, pkg.devDependencies);
    for (let dep in deps) {
      const pattern = /^(@.*\/)?parcel-plugin-.+/;
      if (pattern.test(dep)) {
        let plugin = await localRequire(dep, relative);
        await plugin(this);
      }
    }
github smapiot / piral / src / packages / piral-cli / src / apps / build-piral.ts View on Github external
} = options;
  const entryFiles = await retrievePiralRoot(baseDir, entry);
  const targetDir = dirname(entryFiles);
  const { name, version, root, dependencies, ...pilets } = await retrievePiletsInfo(entryFiles);
  const { externals } = pilets;
  const dest = getDestination(entryFiles, resolve(baseDir, target));

  await checkCliCompatibility(root);

  if (fresh) {
    await clearCache(root, cacheDir);
  }

  await removeDirectory(dest.outDir);

  modifyBundlerForPiral(Bundler.prototype, targetDir);

  // everything except release -> build develop
  if (type !== 'release') {
    logInfo('Starting build ...');

    // we'll need this info for later
    const originalPackageJson = resolve(root, 'package.json');
    const { files: originalFiles = [] } = require(originalPackageJson);
    const appDir = 'app';
    const outDir = await bundleFiles(name, true, targetDir, externals, entryFiles, dest, join('develop', appDir), {
      cacheDir,
      watch: false,
      sourceMaps,
      contentHash,
      minify,
      scopeHoist,
github smapiot / piral / src / packages / piral-cli / src / apps / debug-piral.ts View on Github external
if (krasConfig.injectors === undefined) {
    krasConfig.injectors = defaultConfig.injectors;
  }

  if (fresh) {
    await clearCache(root, cacheDir);
  }

  await setStandardEnvs({
    target: dirname(entryFiles),
    dependencies: externals,
    piral: name,
  });

  modifyBundlerForPiral(Bundler.prototype, dirname(entryFiles));

  const bundler = new Bundler(
    entryFiles,
    extendConfig({ publicUrl, logLevel, cacheDir, scopeHoist, hmr, autoInstall }),
  );

  const injectorConfig = {
    active: true,
    handle: ['/'],
    bundler,
  };

  extendBundlerForPiral(bundler);
  extendBundlerWithPlugins(bundler);

  krasConfig.map['/'] = '';
github smapiot / piral / src / packages / piral-cli / src / common / debug.ts View on Github external
}

  if (krasConfig.api === undefined) {
    krasConfig.api = '/manage-mock-server';
  }

  const buildServerPort = await getFreePort(defaultDevServerPort);

  if (fresh) {
    await clearCache(root);
  }

  await setStandardEnvs(options);

  if (options.dependencies) {
    modifyBundlerForPiral(Bundler.prototype, options.target);
  }

  const bundler = new Bundler(
    entry,
    extendConfig({
      publicUrl,
      logLevel,
    }),
  );

  if (options.dependencies) {
    extendBundlerForPiral(bundler);
  }

  extendBundlerWithPlugins(bundler);
github smapiot / piral / src / packages / piral-cli / src / apps / debug-pilet.ts View on Github external
if (krasConfig.injectors === undefined) {
    krasConfig.injectors = defaultConfig.injectors;
  }

  if (fresh) {
    await clearCache(root, cacheDir);
  }

  await setStandardEnvs({
    target: targetDir,
    piral: appPackage.name,
    dependencies: externals,
  });

  modifyBundlerForPilet(Bundler.prototype, externals, targetDir);

  const bundler = new Bundler(
    entryModule,
    extendConfig({
      logLevel,
      hmr: false,
      minify: true,
      scopeHoist,
      publicUrl: './',
      cacheDir,
      autoInstall,
    }),
  );

  const api = debugPiletApi;
  const injectorConfig = {
github smapiot / piral / src / packages / piral-cli / src / apps / build-pilet.ts View on Github external
production: true,
    piral: appPackage.name,
    target: targetDir,
  });

  const dest = {
    outDir: dirname(resolve(baseDir, target)),
    outFile: basename(target),
  };

  if (fresh) {
    await clearCache(root, cacheDir);
    await removeDirectory(dest.outDir);
  }

  modifyBundlerForPilet(Bundler.prototype, externals, targetDir);

  const bundler = new Bundler(
    entryModule,
    extendConfig({
      ...dest,
      cacheDir,
      watch: false,
      sourceMaps,
      minify,
      scopeHoist,
      contentHash,
      publicUrl: './',
      detailedReport,
      logLevel,
    }),
  );