Skip to content

Commit

Permalink
* Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 1, 2020
1 parent 80a3713 commit 78484a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
4 changes: 0 additions & 4 deletions cli/run/stdin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export function stdinPlugin(): Plugin {

function readStdin(): Promise<string> {
return new Promise((resolve, reject) => {
if (typeof process == 'undefined' || typeof process.stdin == 'undefined') {
return reject(new Error('stdin input is invalid in browser'));
}

const chunks: Buffer[] = [];
process.stdin.setEncoding('utf8');
process.stdin
Expand Down
27 changes: 27 additions & 0 deletions docs/01-command-line-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Many options have command line equivalents. In those cases, any arguments passed
--silent Don't print warnings
--sourcemapExcludeSources Do not include source code in source maps
--sourcemapFile <file> Specify bundle position for source maps
--stdin read input from stdin
--strictDeprecations Throw errors for deprecated features
--no-treeshake Disable tree-shaking optimisations
--no-treeshake.annotations Ignore pure call annotations
Expand Down Expand Up @@ -306,3 +307,29 @@ npm run build -- --environment BUILD:development
```

then the config file will receive `process.env.INCLUDE_DEPS === 'true'` and `process.env.BUILD === 'development'`.

#### `--stdin`

Read input from `stdin` instead of a file. This is the default when no config file is used and no entry point is provided and allows piping content to Rollup. When using a config file, this will replace `input` with what is read from `stdin`. See also [Reading a file from stdin](guide/en/#reading-a-file-from-stdin).

#### `--no-stdin`

Do not read input from `stdin`. Setting this flag will also make sure Rollup interprets `-` as a regular file name instead of interpreting this as the name of `stdin`. See also [Reading a file from stdin](guide/en/#reading-a-file-from-stdin).

### Reading a file from stdin

When using the command line interface, Rollup can also read content from stdin:

```
echo "export const foo = 42;" | rollup --format cjs --file out.js
```

When this file contains imports, Rollup will try to resolve them relative to the current working directory. When a config file is used, Rollup will only use `stdin` as an entry point if either the entry point is called `-` or you pass the [`--stdin`](guide/en/#--stdin) flag. To read a non-entry-point file from stdin, just call it `-`, which is the file name that is used internally to reference `stdin`. I.e.

```js
import foo from "-";
```

in any file will prompt Rollup to try to read the imported file from `stdin`. You can pass the [`--no-stdin`](guide/en/#--no-stdin) CLI flag to Rollup to treat `-` as a regular file name instead.

The JavaScript API will always treat `-` as a regular file name.

0 comments on commit 78484a9

Please sign in to comment.