rollup / rollup-watch

Fast incremental rebuilds with Rollup CLI
MIT License
91 stars 23 forks source link

check if in watch mode in rollup.config.js #48

Closed gerwinbrunner closed 7 years ago

gerwinbrunner commented 7 years ago

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.

Rich-Harris commented 7 years ago

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: https://github.com/rollup/rollup/issues/1429

meszaros-lajos-gyorgy commented 7 years ago

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')
Rich-Harris commented 7 years ago

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()
  ]
};
meszaros-lajos-gyorgy commented 7 years ago

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

bertday commented 6 years ago

+1 for adding this to the docs :)