├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── index.js ├── package-lock.json └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # rollup-plugin-run changelog 2 | 3 | ## 1.1.0 4 | 5 | * Allow arguments and options to be passed to `child_process.fork` 6 | 7 | ## 1.0.2 8 | 9 | * Warn if Rollup version is too low 10 | 11 | ## 1.0.1 12 | 13 | * Handle output files with different names from input files 14 | 15 | ## 1.0.0 16 | 17 | * First release -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Rich Harris 2 | 3 | Permission is hereby granted by the authors of this software, to any person, to use the software for any purpose, free of charge, including the rights to run, read, copy, change, distribute and sell it, and including usage rights to any patents the authors may hold on it, subject to the following conditions: 4 | 5 | This license, or a link to its text, must be included with all copies of the software and any derivative works. 6 | 7 | Any modification to the software submitted to the authors may be incorporated into the software under the terms of this license. 8 | 9 | The software is provided "as is", without warranty of any kind, including but not limited to the warranties of title, fitness, merchantability and non-infringement. The authors have no obligation to provide support or updates for the software, and may not be held liable for any damages, claims or other liability arising from its use. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Moved 2 | 3 | This module has moved and is now available at [@rollup/plugin-run](https://github.com/rollup/plugins). Please update your dependencies. This repository is no longer maintained. 4 | 5 | # rollup-plugin-run 6 | 7 | Run your bundles in Node once they're built. 8 | 9 | ## Why 10 | 11 | You're building a Node app with Rollup. During development, you want to restart the app each time your source code changes. One way to solve that would be to use [nodemon](https://nodemon.io/) targeted at Rollup's output, but that's a bit like using a bazooka to kill a fly. 12 | 13 | Instead, you can add this simple plugin, which gives much faster results. 14 | 15 | ## What 16 | 17 | Each time your bundle is rebuilt, this plugin starts the generated file as a child process (after first closing the previous process, if it's not the first run). 18 | 19 | It 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. 20 | 21 | ## How 22 | 23 | Install it in the usual manner... 24 | 25 | ```bash 26 | npm i -D rollup-plugin-run 27 | ``` 28 | 29 | ...then add it to your config: 30 | 31 | ```js 32 | // rollup.config.js 33 | import run from 'rollup-plugin-run'; 34 | 35 | export default { 36 | input: 'src/index.js', 37 | output: { 38 | file: 'dist/index.js', 39 | format: 'cjs' 40 | }, 41 | plugins: [ 42 | run() 43 | ] 44 | }; 45 | ``` 46 | 47 | Note that we're using the `cjs` format, because we're running the app in Node. 48 | 49 | The app is run in a child process using [child_process.fork(...)](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options). You can pass through options such as `env` and `execArgv`. For example, to debug with sourcemaps using [source-map-support](https://www.npmjs.com/package/source-map-support) you could do this: 50 | 51 | ```diff 52 | // rollup.config.js 53 | import run from 'rollup-plugin-run'; 54 | 55 | export default { 56 | input: 'src/index.js', 57 | output: { 58 | file: 'dist/index.js', 59 | format: 'cjs', 60 | + sourcemap: true 61 | }, 62 | plugins: [ 63 | - run() 64 | + run({ 65 | + execArgv: ['-r', 'source-map-support/register'] 66 | + }) 67 | ] 68 | }; 69 | ``` 70 | 71 | ## When 72 | 73 | By default, always. Since this feature is intended for development use, you may prefer to only include it when Rollup is being run in watch mode: 74 | 75 | ```diff 76 | // rollup.config.js 77 | import run from 'rollup-plugin-run'; 78 | 79 | +const dev = process.env.ROLLUP_WATCH === 'true'; 80 | 81 | export default { 82 | input: 'src/index.js', 83 | output: { 84 | file: 'dist/index.js', 85 | format: 'cjs' 86 | }, 87 | plugins: [ 88 | - run() 89 | + dev && run() 90 | ] 91 | }; 92 | ``` 93 | 94 | ## License 95 | 96 | [LIL](LICENSE) 97 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const child_process = require('child_process'); 3 | 4 | module.exports = (opts = {}) => { 5 | let input; 6 | let proc; 7 | 8 | const args = opts.args || []; 9 | const forkOptions = opts.options || opts; 10 | delete forkOptions.args; 11 | 12 | return { 13 | name: 'run', 14 | 15 | options(opts) { 16 | let inputs = opts.input; 17 | 18 | if (typeof inputs === "string") { 19 | inputs = [inputs]; 20 | } 21 | 22 | if (typeof inputs === "object") { 23 | inputs = Object.values(inputs); 24 | } 25 | 26 | if (inputs.length > 1) { 27 | throw new Error(`rollup-plugin-run only works with a single entry point`); 28 | } 29 | 30 | input = path.resolve(inputs[0]); 31 | }, 32 | 33 | generateBundle(outputOptions, bundle, isWrite) { 34 | if (!isWrite) { 35 | this.error(`rollup-plugin-run currently only works with bundles that are written to disk`); 36 | } 37 | 38 | const dir = outputOptions.dir || path.dirname(outputOptions.file); 39 | 40 | let dest; 41 | 42 | for (const fileName in bundle) { 43 | const chunk = bundle[fileName]; 44 | 45 | if (!('isEntry' in chunk)) { 46 | this.error(`rollup-plugin-run requires Rollup 0.65 or higher`); 47 | } 48 | 49 | if (!chunk.isEntry) continue; 50 | 51 | if (chunk.modules[input]) { 52 | dest = path.join(dir, fileName); 53 | break; 54 | } 55 | } 56 | 57 | if (dest) { 58 | if (proc) proc.kill(); 59 | proc = child_process.fork(dest, args, forkOptions); 60 | } else { 61 | this.error(`rollup-plugin-run could not find output chunk`); 62 | } 63 | } 64 | } 65 | }; -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rollup-plugin-run", 3 | "version": "1.0.2", 4 | "lockfileVersion": 1 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rollup-plugin-run", 3 | "version": "1.1.0", 4 | "description": "Run your bundle after you've built it", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/rollup/rollup-plugin-run.git" 12 | }, 13 | "keywords": [ 14 | "rollup" 15 | ], 16 | "author": "Rich Harris", 17 | "license": "ISC", 18 | "bugs": { 19 | "url": "https://github.com/rollup/rollup-plugin-run/issues" 20 | }, 21 | "homepage": "https://github.com/rollup/rollup-plugin-run#readme" 22 | } 23 | --------------------------------------------------------------------------------