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: CHANGELOG.md
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,9 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
5
5
## Master
6
6
7
7
- Fix `Sprockets::Server` to return lower-cased response headers to comply with Rack::Lint 3.0. [#744](https://github.com/rails/sprockets/pull/744)
8
+
- Adding new directive `depend_on_directory`[#668](https://github.com/rails/sprockets/pull/668)
Copy file name to clipboardExpand all lines: README.md
+47-4Lines changed: 47 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -119,6 +119,7 @@ Here is a list of the available directives:
119
119
-[`link_directory`](#link_directory) - Make target directory compile and be publicly available without adding contents to current
120
120
-[`link_tree`](#link_tree) - Make target tree compile and be publicly available without adding contents to current
121
121
-[`depend_on`](#depend_on) - Recompile current file if target has changed
122
+
-[`depend_on_directory`](#depend_on_directory) - Recompile current file if any files in target directory has changed
122
123
-[`stub`](#stub) - Ignore target file
123
124
124
125
You can see what each of these does below.
@@ -239,7 +240,7 @@ The first time this file is compiled the `application.js` output will be written
239
240
240
241
So, if `b.js` changes it will get recompiled. However instead of having to recompile the other files from `a.js` to `z.js` since they did not change, we can use the prior intermediary files stored in the cached values . If these files were expensive to generate, then this "partial" asset cache strategy can save a lot of time.
241
242
242
-
Directives such as `require`, `link`, and `depend_on` tell Sprockets what assets need to be re-compiled when a file changes. Files are considered "fresh" based on their mtime on disk and a combination of cache keys.
243
+
Directives such as `require`, `link`, `depend_on`, and `depend_on_directory` tell Sprockets what assets need to be re-compiled when a file changes. Files are considered "fresh" based on their mtime on disk and a combination of cache keys.
243
244
244
245
On Rails you can force a "clean" install by clearing the `public/assets` and `tmp/cache/assets` directories.
245
246
@@ -453,11 +454,53 @@ you need to tell sprockets that it needs to re-compile the file if `bar.data` ch
453
454
var bar ='<%= File.read("bar.data") %>'
454
455
```
455
456
457
+
To depend on an entire directory containing multiple files, use `depend_on_directory`
458
+
456
459
### depend_on_asset
457
460
458
461
`depend_on_asset`*path* works like `depend_on`, but operates
459
462
recursively reading the file and following the directives found. This is automatically implied if you use `link`, so consider if it just makes sense using `link` instead of `depend_on_asset`.
460
463
464
+
### depend_on_directory
465
+
466
+
`depend_on_directory`*path* declares all files in the given *path* without
467
+
including them in the bundle. This is useful when you need to expire an
468
+
asset's cache in response to a change in multiple files in a single directory.
469
+
470
+
All paths are relative to your declaration and must begin with `./`
471
+
472
+
Also, your must include these directories in your [load path](guides/building_an_asset_processing_framework.md#the-load-path).
473
+
474
+
**Example:**
475
+
476
+
If we've got a directory called `data` with files `a.data` and `b.data`
477
+
478
+
```
479
+
// ./data/a.data
480
+
A
481
+
```
482
+
483
+
```
484
+
// ./data/b.data
485
+
B
486
+
```
487
+
488
+
```
489
+
// ./file.js.erb
490
+
//= depend_on_directory ./data
491
+
var a = '<% File.read('data/a.data') %>'
492
+
var b = '<% File.read('data/b.data') %>'
493
+
```
494
+
495
+
Would produce:
496
+
497
+
```js
498
+
var a ="A";
499
+
var b ="B";
500
+
```
501
+
502
+
You can also see [Index files are proxies for folders](#index-files-are-proxies-for-folders) for another method of organizing folders that will give you more control.
503
+
461
504
### stub
462
505
463
506
`stub`*path* excludes that asset and its dependencies from the asset bundle.
@@ -499,9 +542,9 @@ When you modify the `logo.png` on disk, it will force `application.css` to be
499
542
recompiled so that the fingerprint will be correct in the generated asset.
500
543
501
544
You can manually make sprockets depend on any other file that is generated
502
-
by sprockets by using the `depend_on` directive. Rails implements the above
503
-
feature by auto calling `depend_on` on the original asset when the `asset_url`
504
-
is used inside of an asset.
545
+
by sprockets by using the `depend_on`or `depend_on_directory`directive. Rails
546
+
implements the above feature by auto calling `depend_on` on the original asset
0 commit comments