Skip to content

Commit 67c144b

Browse files
authored
Merge pull request #356 from js-kyle/cli_docs
MINOR Added extra cdn and cli docs
2 parents 80ce7ad + 04ce302 commit 67c144b

File tree

1 file changed

+50
-7
lines changed

1 file changed

+50
-7
lines changed

README.md

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,13 @@ app.use(require("connect-assets")(options, function (instance) {
180180
}));
181181
```
182182
183-
## Serving Assets from a CDN
183+
## CLI
184184
185185
connect-assets includes a command-line utility, `connect-assets`, which can be used to precompile assets on your filesystem (which you can then upload to your CDN of choice). From your application directory, you can execute it with `./node_modules/.bin/connect-assets [options]`.
186-
187186
```
188187
Usage: connect-assets [-h] [-v] [-gz] [-ap] [-i [DIRECTORY [DIRECTORY ...]]]
189188
[-c [FILE [FILE ...]]] [-o DIRECTORY]
190189
191-
Precompiles assets supplied into their production-ready form, ready for
192-
upload to a CDN or static file server. The generated manifest.json is all
193-
that is required on your application server if connect-assets is properly
194-
configured.
195-
196190
Optional arguments:
197191
-h, --help Show this help message and exit.
198192
-v, --version Show program's version number and exit.
@@ -223,6 +217,55 @@ Optional arguments:
223217
Do not add XSSI protection header to source map files.
224218
https://github.com/adunkman/connect-assets/issues/345#issuecomment-235246691
225219
```
220+
### CLI examples
221+
**Basic use case:**
222+
Compile contents of public/javascripts folder, saving to a the cdn directory.
223+
`connect-assets -i public/javascripts -o cdnassets`
224+
225+
**Advanced use case (nested directories):**
226+
When compiling files which use Sprockets style concatenation e.g. `//= require dependency`, the path to the dependency must also be passed using the `--include` flag.
227+
Consider this project structure:
228+
```
229+
Simple App
230+
│ README.md
231+
│ app.js
232+
└─── public
233+
│ │ robots.txt
234+
│ └─── javascripts
235+
│ │ bundle.js
236+
│ │ sw.js
237+
| | client.js
238+
│ └─── app
239+
| └─── users
240+
│ | users.controller.js
241+
│ | users.routes.js
242+
└─── test
243+
│ users.spec.js
244+
```
245+
Contents of bundle.js:
246+
```
247+
//= require users/users.controller.js
248+
//= require users/users.routes.js
249+
```
250+
In the above scenario `connect-assets -i public/javascripts -o cdnassets` will fail to compile `bundle.js` as connect-assets will fail to find the file on the provided path.
251+
To remove errors, ensure that the paths (the same paths as what are defined in your connect-assets options).
252+
For example, `connect-assets -i public/javascripts -i public/javascripts/app -o cdnassets` will successfully pre-compile `bundle.js`.
253+
254+
## Serving Assets from a CDN
255+
256+
The CLI utility precompiles assets supplied into their production-ready form, ready for
257+
upload to a CDN or static file server. The generated `manifest.json` is all
258+
that is required on your application server if connect-assets is properly
259+
configured. Once assets have been precompiled and uploaded to CDN (perhaps as part of your build process), you can pass the Mincer environment your manifest file like so:
260+
261+
```
262+
const assetManifest = require('./manifest.json');
263+
264+
app.use(require("connect-assets")(options, function (instance) {
265+
instance.manifest = assetManifest;
266+
}));
267+
```
268+
Your CDN url will also need to be passed to the `servePath` option of connect-assets.
226269
227270
## Credits
228271

0 commit comments

Comments
 (0)