You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50-7Lines changed: 50 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -180,19 +180,13 @@ app.use(require("connect-assets")(options, function (instance) {
180
180
}));
181
181
```
182
182
183
-
## Serving Assets from a CDN
183
+
## CLI
184
184
185
185
connect-assets includes acommand-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]`.
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-readyform, 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.
0 commit comments