How to use the parcel-bundler 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 lin-xi / mark / script / dev.es.js View on Github external
import Parcel from 'parcel-bundler'
import path from 'path'
import electron from 'electron'


const option = {
  watch: true,
  // target: 'electron',
  publicUrl: './',
  cache: true,
  hmr: false
}

let index = new Parcel(path.join(__dirname, '../src/index.html'), option)
index.bundle().then(() => {
  console.log('>> done')
  var proc = require('child_process')

  var child = proc.spawn(electron, ['.', '--debug'], {
    stdio: 'inherit'
  })
  child.on('close', function (code) {
    process.exit(code)
  })
})
github ifiokjr / remirror / @remirror / cli / src / commands / bundle / cli-parcel.ts View on Github external
const tempDir = path.join(os.tmpdir(), uniqueId());
  const tempFileName = 'remirror-webview.js';
  const tempFilePath = path.join(tempDir, tempFileName);
  const outDir = workingDirectory;
  const isTs = bool(source.match(/\.tsx?$/));
  const outFilePath = path.join(outDir, isTs ? 'file.ts' : 'file.js');
  // Parcel config
  const options: ParcelOptions = {
    outDir: tempDir,
    outFile: tempFileName,
    sourceMaps: false,
    minify: true,
    watch: false,
    logLevel: 1,
  };
  const parcel = new Bundler(entryFile, options);
  async function build(bundler: Bundler) {
    try {
      // create the bundle
      await bundler.bundle();

      // Read the bundle and insert it into script template
      const script = await readFile(tempFilePath, 'utf-8');
      const finalOutput = isTs ? createTSFile(script) : createJSFile(script);
      await writeFile(outFilePath, finalOutput, 'utf-8');

      // Remove junk
      await clearPath(`${tempDir}/*`);
    } catch (error) {
      console.error(error);
    }
  }
github lin-xi / mark / script / pack.es.js View on Github external
import Parcel from 'parcel-bundler'
import path from 'path'
import fs from 'fs-extra'
const builder = require('electron-builder')

const option = {
  watch: false,
  cache: false,
  // target: 'electron',
  publicUrl: './',
  hmr: false
}

let index = new Parcel(path.join(__dirname, '../src/index.html'), option)
index.bundle().then(() => {
  fs.copySync(path.join(__dirname, '../logo.png'), path.join(__dirname, '../dist/logo.png'))
  fs.copySync(path.join(__dirname, '../logo.svg'), path.join(__dirname, '../dist/logo.svg'))
  fs.copySync(path.join(__dirname, '../src/index.js'), path.join(__dirname, '../dist/index.js'))
  fs.copySync(path.join(__dirname, '../src/auto-updater.js'), path.join(__dirname, '../dist/auto-updater.js'))
  fs.copySync(path.join(__dirname, '../src/services'), path.join(__dirname, '../dist/services'))
  fs.copySync(path.join(__dirname, '../package.json'), path.join(__dirname, '../dist/package.json'))

  console.log('>> done')
  console.log('>> start pack...')

  builder.build({
    config: {
      'appId': 'com.mark.app',
      'productName': 'Mark',
      'directories': {
github threadheap / serverless-plugin-parcel / src / index.ts View on Github external
watch: this.options.watch || false
        };
        const config = {
            ...defaults,
            ...options
        };

        if (this.options.watch) {
            this.isWatching = true;
        }

        if (this.entries.length === 1) {
            // watch single function
            const entry = this.entries[0];

            const bundler = new Bundler(entry, {
                ...config,
                outDir: path.relative(
                    this.originalServicePath,
                    path.join(this.buildPath, path.dirname(entry))
                )
            });

            this.invokeBundle = await bundler.bundle();

            if (this.isWatching) {
                (bundler as any).on('buildEnd', () => {
                    this.sls.pluginManager.spawn('invoke:local');
                });
            }
        } else {
            for (const entry of this.entries) {
github logux / logux.io / scripts / steps / compile-assets.js View on Github external
async function compileAssets () {
  let pugTemplate = join(SRC, 'uikit.pug')
  let uikitBundler = new Bundler(pugTemplate, {
    sourceMaps: false,
    logLevel: 2
  })
  let bundle = await uikitBundler.bundle()
  let assets = findAssets(bundle)
  let hashes = { }
  return {
    map (fn) {
      return assets.map(fn)
    },
    get (regexp) {
      return assets.filter(i => regexp.test(i))
    },
    find (regexp) {
      return assets.find(i => regexp.test(i))
    },
github doczjs / docz / packages / playgrood / src / utils / bundle.ts View on Github external
export const createBundle = async (html: string, main: string) => {
  await trash(DIST_PATH)
  await trash(THEME_PATH)
  await tempFile(INDEX_JS, main)
  await tempFile(INDEX_HTML, html)

  const bundler = new Bundler(INDEX_HTML, {
    cacheDir: CACHE_PATH,
    outDir: DIST_PATH,
    publicURL: '/',
    outFile: 'index',
  })

  try {
    return await bundler.bundle()
  } catch (err) {
    console.log(err)
    return null
  }
}
github threadheap / serverless-plugin-parcel / src / index.ts View on Github external
outDir: path.relative(
                    this.originalServicePath,
                    path.join(this.buildPath, path.dirname(entry))
                )
            });

            this.invokeBundle = await bundler.bundle();

            if (this.isWatching) {
                (bundler as any).on('buildEnd', () => {
                    this.sls.pluginManager.spawn('invoke:local');
                });
            }
        } else {
            for (const entry of this.entries) {
                const bundler = new Bundler(entry, {
                    ...config,
                    outDir: path.relative(
                        this.originalServicePath,
                        path.join(this.buildPath, path.dirname(entry))
                    )
                });

                await bundler.bundle();
            }
        }
    }
github loteoo / hyperstatic / site-generator / generate-site.js View on Github external
const bundlePromises = pages.map(page => {
  const entryFile = path.join(__dirname, '..', 'src', 'pages', page)
  const bundler = new Bundler(entryFile)
  return bundler.bundle()
})
github hmmhmmhm / svelte-template / config / parcel.config.ts View on Github external
export const getBundler = async options => {
    let bundler = new Bundler(template, options)
    await SveltePlugin(bundler)
    return bundler
}