How to use the rollup.watch function in rollup

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 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 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 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;
      }
github mapbox / mapbox-gl-js / test / integration / testem.js View on Github external
return new Promise((resolve, reject) => {
                const watcher = rollup.watch(silenceWarnings(config));
                rollupWatchers[name] = watcher;

                watcher.on('event', (e) => {
                    if (e.code === 'START') {
                        notify('Query Tests', `${name} bundle started`);
                    }
                    if (e.code === 'END') {
                        notify('Query Tests', `${name} bundle finished`);
                        resolve();
                    }
                    if (e.code === 'FATAL') {
                        reject(e);
                    }
                });

            });
github shrynx / nodify / packages / nodify-core / scripts / dev.js View on Github external
let customConfig = {};

  if (fs.existsSync(paths.customConfigPath)) {
    const customConfigModule = require(paths.customConfigPath);
    customConfig = customConfigModule.default || customConfigModule;
  }

  const coreConfig = customConfig.rollup
    ? createConfig(customConfig.rollup(baseConfig(env), env))
    : createConfig(baseConfig(env));

  const rollupConfig = Object.assign({}, coreConfig.inputOptions, {
    output: coreConfig.outputOptions,
  });

  watcher = rollup.watch(rollupConfig);

  watcher.on('event', event => {
    switch (event.code) {
      case 'FATAL':
        screen.close();
        handleError(event.error, true);
        process.exit();
        break;

      case 'ERROR':
        screen.reset('');
        warnings.flush();
        handleError(event.error, true);
        break;

      case 'START':
github 1stG / configs / packages / rollup-config / cli.js View on Github external
const startWatcher = configs => {
  const watcher = watch(configs)
  watcher.on('event', event => {
    switch (event.code) {
      case 'START':
        info('🚀 (re)starting...')
        break
      case 'END':
        info('🎉 bundled successfully.')
        break
      case 'ERROR':
        console.error(event)
        break
      case 'FATAL':
        console.error(event)
        watcher.close()
        break
    }
github kallsave / vue-router-cache / scripts / dev.js View on Github external
return new Promise((resolve) => {
        const watcher = rollup.watch(build)
        watcher.on('event', event => {
          console.log(event.code)
          if (event.code === 'END') {
            copy('dist', `examples/${EXAMPLE}/src/plugins/${name}/`, function (err) {
              console.log(err)
            })
            resolve()
          }
        })
      })
    })()
github umijs / father / packages / father-build / src / rollup.ts View on Github external
async function build(entry: string, opts: IRollupOpts) {
  const { cwd, type, log, bundleOpts, importLibToEs } = opts;
  const rollupConfigs = getRollupConfig({
    cwd,
    type,
    entry,
    importLibToEs,
    bundleOpts: normalizeBundleOpts(entry, bundleOpts),
  });

  for (const rollupConfig of rollupConfigs) {
    if (opts.watch) {
      const watcher = watch([
        {
          ...rollupConfig,
          watch: {},
        },
      ]);
      watcher.on('event', event => {
        if (event.error) {
          signale.error(event.error);
        } else if (event.code === 'START') {
          log(`[${type}] Rebuild since file changed`);
        }
      });
      process.once('SIGINT', () => {
        watcher.close();
      });
    } else {