Skip to content

Latest commit

 

History

History
 
 

run

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

npm size libera manifesto

@rollup/plugin-run

🍣 A Rollup plugin which runs your bundles in Node once they're built.

Using this plugin gives much faster results compared to what you would do with nodemon.

Install

Using npm:

npm install @rollup/plugin-run --save-dev

Usage

Create a rollup.config.js configuration file and import the plugin:

import run from '@rollup/plugin-run';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/index.js',
    format: 'cjs'
  },
  plugins: [run()]
};

Then call rollup either via the CLI or the API. If the build produces any errors, the plugin will write a 'alias' character to stderr, which should be audible on most systems.

The plugin forks a child process with the generated file, every time the bundle is rebuilt (after first closing the previous process, if it's not the first run).

Note: This plugin works with Rollup's code-splitting if you're using dynamic import(...) — the only constraint is that you have a single entry point specified in the config.

Options

This plugin supports pass through option available for child_process.fork(...).

Example:

Debugging with sourcemaps using source-map-support:

// rollup.config.js
import run from '@rollup/plugin-run';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/index.js',
    format: 'cjs',
+    sourcemap: true
  },
  plugins: [
-    run()
+    run({
+      execArgv: ['-r', 'source-map-support/register']
+    })
  ]
};

Practical Example

The feature is usually intended for development use, you may prefer to only include it when Rollup is being run in watch mode:

// rollup.config.js
import run from '@rollup/plugin-run';

+const dev = process.env.ROLLUP_WATCH === 'true';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/index.js',
    format: 'cjs'
  },
  plugins: [
-    run()
+    dev && run()
  ]
};

Meta

CONTRIBUTING

LICENSE (MIT)