Browse Source

Merge pull request #699 from rollup/watch

rollup --watch
ghi-672
Rich Harris 9 years ago
parent
commit
cc908eef62
  1. 8
      bin/handleError.js
  2. 1
      bin/help.md
  3. 3
      bin/rollup
  4. 40
      bin/runRollup.js
  5. 1
      package.json

8
bin/handleError.js

@ -27,6 +27,14 @@ var handlers = {
DUPLICATE_IMPORT_OPTIONS: function ( err ) {
console.error( chalk.red( 'use --input, or pass input path as argument' ) );
},
ROLLUP_WATCH_NOT_INSTALLED: function ( err ) {
console.error( chalk.red( 'rollup --watch depends on the rollup-watch package, which could not be found. You can install it globally (recommended) with ' ) + chalk.cyan( 'npm install -g rollup-watch' ) );
},
WATCHER_MISSING_INPUT_OR_OUTPUT: function ( err ) {
console.error( chalk.red( 'must specify --input and --output when using rollup --watch' ) );
}
};

1
bin/help.md

@ -9,6 +9,7 @@ Basic options:
-h, --help Show this help message
-c, --config Use this config file (if argument is used but value
is unspecified, defaults to rollup.config.js)
-w, --watch Watch files in bundle and rebuild on changes
-i, --input Input (alternative to <entry file>)
-o, --output <output> Output (if absent, prints to stdout)
-f, --format [es6] Type of output (amd, cjs, es6, iife, umd)

3
bin/rollup

@ -20,7 +20,8 @@ command = minimist( process.argv.slice( 2 ), {
n: 'name',
o: 'output',
u: 'id',
v: 'version'
v: 'version',
w: 'watch'
}
});

40
bin/runRollup.js

@ -1,7 +1,9 @@
require( 'source-map-support' ).install();
var path = require( 'path' );
var relative = require( 'require-relative' );
var handleError = require( './handleError' );
var chalk = require( 'chalk' );
var rollup = require( '../' );
// log to stderr to keep `rollup main.js > bundle.js` from breaking
@ -127,7 +129,43 @@ function execute ( options, command ) {
});
try {
bundle( options ).catch( handleError );
if ( command.watch ) {
if ( !options.entry || !options.dest ) {
handleError({ code: 'WATCHER_MISSING_INPUT_OR_OUTPUT' });
}
try {
var watch = relative( 'rollup-watch', process.cwd() );
var watcher = watch( rollup, options );
watcher.on( 'event', function ( event ) {
switch ( event.code ) {
case 'STARTING':
console.error( 'checking rollup-watch version...' );
break;
case 'BUILD_START':
console.error( 'bundling...' );
break;
case 'BUILD_END':
console.error( 'bundled in ' + event.duration + 'ms. Watching for changes...' );
break;
default:
console.error( 'unknown event', event );
}
});
} catch ( err ) {
if ( err.code === 'MODULE_NOT_FOUND' ) {
err.code = 'ROLLUP_WATCH_NOT_INSTALLED';
}
handleError( err );
}
} else {
bundle( options ).catch( handleError );
}
} catch ( err ) {
handleError( err );
}

1
package.json

@ -63,6 +63,7 @@
"dependencies": {
"chalk": "^1.1.1",
"minimist": "^1.2.0",
"require-relative": "^0.8.7",
"source-map-support": "^0.4.0"
},
"files": [

Loading…
Cancel
Save