|
17 | 17 |
|
18 | 18 | [](https://greenkeeper.io/)
|
19 | 19 |
|
20 |
| -A module that takes any number of css file entry points and packages them together with meta data before providing them as a readable stream. |
| 20 | +A module that takes any number of css file entry points and packages them |
| 21 | +together with meta data before providing them as a readable stream. |
21 | 22 |
|
22 | 23 | ## Overview
|
23 | 24 |
|
24 | 25 | Given any number of css file paths, for each file path, this module will:
|
| 26 | + |
25 | 27 | 1. fetch the file at the path
|
26 | 28 | 2. fetch a name and version from the nearest package.json to the file
|
27 |
| -3. bundle the css found in the file (resolving any @import statements and inlining them) |
| 29 | +3. bundle the css found in the file (resolving any @import statements and |
| 30 | + inlining them) |
28 | 31 | 4. put all this together in an object (See Output data format below)
|
29 | 32 |
|
30 | 33 | The module provides a readable stream of the resulting objects.
|
@@ -55,43 +58,53 @@ npm install asset-pipe-css-writer
|
55 | 58 | ## Usage
|
56 | 59 |
|
57 | 60 | ### Require the writer
|
| 61 | + |
58 | 62 | ```js
|
59 |
| -const CssWriter = require('asset-pipe-css-writer') |
| 63 | +const CssWriter = require('asset-pipe-css-writer'); |
60 | 64 | ```
|
61 | 65 |
|
62 | 66 | ### Instantiating the writer
|
63 | 67 |
|
64 | 68 | Either pass a path to a single css file:
|
| 69 | + |
65 | 70 | ```js
|
66 |
| -const writer = new CssWriter('/path/to/css/file.css') |
| 71 | +const writer = new CssWriter('/path/to/css/file.css'); |
67 | 72 | ```
|
68 | 73 |
|
69 | 74 | Or pass an array of paths to css files:
|
| 75 | + |
70 | 76 | ```js
|
71 |
| -const writer = new CssWriter(['/path/to/css/file1.css', '/path/to/css/file2.css']) |
| 77 | +const writer = new CssWriter([ |
| 78 | + '/path/to/css/file1.css', |
| 79 | + '/path/to/css/file2.css', |
| 80 | +]); |
72 | 81 | ```
|
73 | 82 |
|
74 | 83 | ### Consuming content from the writer
|
75 | 84 |
|
76 |
| -The writer is a readable stream in object mode so in order to access the data you may register a data handler |
77 |
| -and listen for objects to be passed to the handler: |
| 85 | +The writer is a readable stream in object mode so in order to access the data |
| 86 | +you may register a data handler and listen for objects to be passed to the |
| 87 | +handler: |
| 88 | + |
78 | 89 | ```js
|
79 | 90 | writer.on('data', data => {
|
80 | 91 | // { id, name, version, file, content }
|
81 |
| -}) |
| 92 | +}); |
82 | 93 | ```
|
83 | 94 |
|
84 |
| -You might also pipe the writer into a writeable or transform stream (with input in object mode): |
| 95 | +You might also pipe the writer into a writeable or transform stream (with input |
| 96 | +in object mode): |
| 97 | + |
85 | 98 | ```js
|
86 |
| -const { Writable } = require('stream') |
| 99 | +const { Writable } = require('stream'); |
87 | 100 | const consumer = new Writeable({
|
88 | 101 | objectMode: true,
|
89 | 102 | write(chunk, encoding, callback) {
|
90 | 103 | // chunk will be an object of the shape: { id, name, version, file, content }
|
91 |
| - console.log(chunk) |
92 |
| - callback() |
93 |
| - } |
94 |
| -}) |
| 104 | + console.log(chunk); |
| 105 | + callback(); |
| 106 | + }, |
| 107 | +}); |
95 | 108 |
|
96 |
| -writer.pipe(consumer) |
| 109 | +writer.pipe(consumer); |
97 | 110 | ```
|
0 commit comments