rollup/rollup-watch

check if in watch mode in rollup.config.js

Closed this issue · 5 comments

Is there a way to figure out if the rollup was started with the --watch flag?

I'm trying to figure out in rollup.config.js if the watch flag is set to skip the liverelode and serve plugin.

Agree — I'm planning to add a process.env.ROLLUP_WATCH environment variable, which would be "true" or undefined. That sound like a sensible solution? Related issue: rollup/rollup#1429

A temporary solution, which works for me is to have this line of code in my rollup.config.js:

const isWatching = process.argv.includes('-w') || process.argv.includes('--watch')

This was recently added to Rollup itself, so I'll close this. My rollup.config.js files often look like this now:

import uglify from 'rollup-plugin-uglify';

// dev build if watching, prod build if not
const production = !process.env.ROLLUP_WATCH;

export default {
  entry: 'src/main.js',
  dest: 'public/bundle.js',
  format: 'iife',
  plugins: [
    prod && uglify()
  ]
};

Can you please add a note on this in the documentation?

+1 for adding this to the docs :)