How to use rollup - 10 common examples

To help you get started, we’ve selected a few rollup 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 jitsucom / jitsu / javascript-sdk / __tests__ / common / devserver.ts View on Github external
(async function() {
  process.env.NODE_ENV = 'development';

  let rollupFile = `${__dirname}/../../rollup.config.js`;
  console.log(`Loading rollup file ${rollupFile}`);
  const { options, warnings } = await loadConfigFile(path.resolve(rollupFile), { format: 'es' });

  // This prints all deferred warnings
  warnings.flush();

  for (const optionsObj of options) {
    const bundle = await rollup.rollup(optionsObj);
    await Promise.all(optionsObj.output.map(bundle.write));
  }

  // You can also pass this directly to "rollup.watch"
  const watcher = rollup.watch(options);

  watcher.on('event', (event) => {
    if (event.code === 'START') {
      console.log('Building output bundles...')
    } else if (event.code === 'END') {
github TracerBench / tracerbench / packages / parse-profile / serve.js View on Github external
const http = require('http');
const serveStatic = require('serve-static');
const rollup = require('rollup');
const path = require('path');

const serve = serveStatic(__dirname, { index: ['index.html'] });

// Create server
var server = http.createServer(function onRequest(req, res) {
  serve(req, res, finalhandler(req, res));
});

server.listen(3000);
console.error('listening on http://127.0.0.1:3000');

const watcher = rollup.watch(require('./rollup.config'));

watcher.on('event', function(event) {
  switch (event.code) {
    case 'FATAL':
      console.error(event.error);
      process.exit(1);
      break;
    case 'ERROR':
      console.error(event.error);
      break;
    case 'START':
      break;
    case 'BUNDLE_START':
      console.error('bundle ' + event.input);
      break;
    case 'BUNDLE_END':
github MikeKovarik / rollup-plugin-notify / index.js View on Github external
const path = require('path')
const notifier = require('node-notifier')
const stripAnsi = require('strip-ansi')
const {charSizes} = require('./font.js')
const rollup = require('rollup')


// Warning that this plugin requies at least rollup 0.60.0.
if (rollup.VERSION) {
	let [major, minor, patch] = rollup.VERSION.split('.').map(Number)
	if (major < 1 && minor < 60)
		console.warn(`'rollup-plugin-notify' will not work. Rollup 0.60.0 or higher is required`)
}

// Ugly hack. There are two problems (not 100% sure but this is what's most likely going on)
// 1) Rollup apparently terminates the process immediately after error occurs.
//    It calls the buildEnd callback but does not give us enough time to create the notification asynchronously.
// 2) node-notifier creates the notification by calling child_process.execFile() which is not as reliable
//    as just child_process.exec(). But exec() wouldn't support multiline notifications due to inability to pass
//    EOLs in cmd arguments.
// This hack creates the notification synchronously and bypassess node-notifier's internals.
// Tested on Windows 10. Not sure if the same problem/hack occurs/is-needed on other systems too.
const os = require('os')
if (os.platform() === 'win32' && os.release().startsWith('10.')) {
	notifier.notify = function(options) {
github MikeKovarik / rollup-plugin-notify / index.js View on Github external
const path = require('path')
const notifier = require('node-notifier')
const stripAnsi = require('strip-ansi')
const {charSizes} = require('./font.js')
const rollup = require('rollup')


// Warning that this plugin requies at least rollup 0.60.0.
if (rollup.VERSION) {
	let [major, minor, patch] = rollup.VERSION.split('.').map(Number)
	if (major < 1 && minor < 60)
		console.warn(`'rollup-plugin-notify' will not work. Rollup 0.60.0 or higher is required`)
}

// Ugly hack. There are two problems (not 100% sure but this is what's most likely going on)
// 1) Rollup apparently terminates the process immediately after error occurs.
//    It calls the buildEnd callback but does not give us enough time to create the notification asynchronously.
// 2) node-notifier creates the notification by calling child_process.execFile() which is not as reliable
//    as just child_process.exec(). But exec() wouldn't support multiline notifications due to inability to pass
//    EOLs in cmd arguments.
// This hack creates the notification synchronously and bypassess node-notifier's internals.
// Tested on Windows 10. Not sure if the same problem/hack occurs/is-needed on other systems too.
const os = require('os')
if (os.platform() === 'win32' && os.release().startsWith('10.')) {
	notifier.notify = function(options) {
		var {title, message, icon} = options
github axa-ch / patterns-library / stack / tasks / bundles / polyfill.js View on Github external
async function buildPolyfills() {
  const bundle = await rollup.rollup(common.inputOptions);
  const file = common.adaptSlashes(`${CWD}/${ENV === constants.ENV.PROD ? 'dist' : '.tmp'}/app/es6-polyfills.js`);
  // console.log(`Styleguide Bundel: ${file}`); // eslint-disable-line
  // or write the bundle to disk
  await bundle.write({
    ...common.outputOptions,
    file,
  });
}
github mvdom / mvdom / scripts / src / cmds.ts View on Github external
// if we have some globals, we add them accordingly
	if (opts.globals) {
		// for input, just set the external (clone to be safe(r))
		inputOptions.external = Object.keys(opts.globals);
		outputOptions.globals = opts.globals;
	}

	try {
		// if it is watch mode, we do the watch
		if (opts.watch) {
			//wathOptions = { inputOptions };
			let watchOptions = { ...inputOptions };
			watchOptions.output = outputOptions;
			watchOptions.watch = { chokidar: true };

			const watcher = rollup.watch(watchOptions);
			let startTime: number;

			watcher.on('event', function (evt) {
				// console.log('rollup watch', evt.code, evt.output);
				if (evt.code === 'START') {
					startTime = now();
				} else if (evt.code === 'END') {
					console.log(`Recompile ${distFile} done: ${Math.round(now() - startTime)}ms`);
				} else if (evt.code === 'ERROR') {
					console.log(`ERROR - Rollup/Typescript error when processing: ${distFile}`);
					console.log("\t" + evt.error);
				} else if (evt.code === 'FATAL') {
					console.log(`FATAL ERROR - Rollup/Typescript fatal error when processing ${distFile}\n
					>>>>>>>> MUST RESTART WATCH SESSION <<<<<<<<\n\n`, evt.error);
				}
			});
github ionic-team / stencil / scripts / build.components.js View on Github external
var rollup = require( 'rollup' );
var fs = require('fs');
var path = require('path');
var ncp = require('ncp').ncp;


var es2015Entry = path.join(__dirname, '../node_modules/ionic-ui/es2015/index.js');
var es2015Dest = es2015Entry;

var npmPackageJsonSource = path.join(__dirname, './npm.package.json');
var npmPackageJsonDest = path.join(path.dirname(es2015Dest), '../package.json');
var npmPackageJsonContent = fs.readFileSync(npmPackageJsonSource).toString();
fs.writeFileSync(npmPackageJsonDest, npmPackageJsonContent);


rollup.rollup({
  entry: es2015Entry

}).then(function (bundle) {
  // Generate bundle + sourcemap
  var result = bundle.generate({
    format: 'es'
  });

  fs.writeFileSync(es2015Dest, result.code);

  var source = path.dirname(es2015Entry, '..');

  deepCopy(source, path.join(__dirname, '../demos/angular/node_modules/ionic-ui'));
});
github preconstruct / preconstruct / packages / cli / src / build / watch.ts View on Github external
async function watchPackage(pkg: Package, aliases: Aliases) {
  const _configs = getRollupConfigs(pkg, aliases);
  await fs.remove(path.join(pkg.directory, "dist"));
  let configs = _configs.map(config => {
    return { ...config.config, output: config.outputs };
  });
  const watcher = watch(configs);
  let reject: (reason?: unknown) => void;
  let errPromise = new Promise((resolve, _reject) => {
    reject = _reject;
  });
  let startResolve: (value?: unknown) => void;
  let startPromise = new Promise(resolve => {
    startResolve = resolve;
  });
  watcher.on("event", event => {
    // https://github.com/rollup/rollup/blob/aed954e4e6e8beabd47268916ff0955fbb20682d/bin/src/run/watch.ts#L71-L115
    switch (event.code) {
      case "FATAL": {
        reject(event.error);
        break;
      }
github alibaba / GGEditor / scripts / start.js View on Github external
function start(name) {
  const contentBase = `examples`;

  // Clean
  rimraf.sync(`${contentBase}/dist`);

  signale.success('Clean success');

  // Watch
  const watcher = rollup.watch({
    input: [`${contentBase}/${name}/index.tsx`],
    output: {
      file: `${contentBase}/dist/bundle.js`,
      format: 'umd',
      globals: {
        react: 'React',
        'react-dom': 'ReactDOM',
        antd: 'antd',
      },
    },
    plugins: [
      postcss({
        modules: {
          camelCase: true,
          generateScopedName: '[local]--[hash:base64:5]',
        },
github keystonejs / keystone / packages / build-field-types / src / build / watch.js View on Github external
async function watchPackage(pkg, aliases) {
  const _configs = getRollupConfigs(pkg, aliases);
  await Promise.all([
    fs.remove(path.join(pkg.directory, 'dist')),
    ...pkg.entrypoints.map(entrypoint => {
      return fs.remove(path.join(entrypoint.directory, 'dist'));
    }),
  ]);
  let configs = _configs.map(config => {
    return { ...toUnsafeRollupConfig(config.config), output: config.outputs };
  });
  const watcher = watch(configs);
  let reject;
  let errPromise = new Promise((resolve, _reject) => {
    reject = _reject;
  });
  let startResolve;
  let startPromise = new Promise(resolve => {
    startResolve = resolve;
  });
  watcher.on('event', event => {
    // https://github.com/rollup/rollup/blob/aed954e4e6e8beabd47268916ff0955fbb20682d/bin/src/run/watch.ts#L71-L115
    switch (event.code) {
      case 'FATAL': {
        reject(event.error);
        break;
      }