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
`depends_on_directory` allows you to specify all files (non-recurisve)
in a directory to watch for changes. This is helpful in cases where
files may be dynamic or there are many files.
Copy file name to clipboardExpand all lines: README.md
+44-4Lines changed: 44 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
@@ -445,11 +446,50 @@ you need to tell sprockets that it needs to re-compile the file if `bar.data` ch
445
446
var bar ='<%= File.read("bar.data") %>'
446
447
```
447
448
449
+
To depend on an entire directory containing multiple files, use `depend_on_directory`
450
+
448
451
### depend_on_asset
449
452
450
453
`depend_on_asset`*path* works like `depend_on`, but operates
451
454
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`.
452
455
456
+
### depend_on_directory
457
+
458
+
`depend_on_directory`*path* declares all files in the given *path* without
459
+
including them in the bundle. This is useful when you need to expire an
460
+
asset's cache in response to a change in multiple files in a single directory.
461
+
462
+
All paths are relative to your declaration and must begin with `./`
463
+
464
+
Also, your must include these directories in your [load path](guides/building_an_asset_processing_framework.md#the-load-path).
465
+
466
+
**Example:**
467
+
468
+
If we've got a directory called `data` with files `a.data` and `b.data`
469
+
470
+
```a.data
471
+
A
472
+
```
473
+
474
+
```b.data
475
+
B
476
+
```
477
+
478
+
```js.erb
479
+
//= depend_on_directory ./data
480
+
var a ='<% File.read('data/a.data') %>'
481
+
var b ='<% File.read('data/b.data') %>'
482
+
```
483
+
484
+
Would produce:
485
+
486
+
```js
487
+
var a ="A";
488
+
var b ="B";
489
+
```
490
+
491
+
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.
492
+
453
493
### stub
454
494
455
495
`stub`*path* excludes that asset and its dependencies from the asset bundle.
@@ -491,9 +531,9 @@ When you modify the `logo.png` on disk, it will force `application.css` to be
491
531
recompiled so that the fingerprint will be correct in the generated asset.
492
532
493
533
You can manually make sprockets depend on any other file that is generated
494
-
by sprockets by using the `depend_on` directive. Rails implements the above
495
-
feature by auto calling `depend_on` on the original asset when the `asset_url`
496
-
is used inside of an asset.
534
+
by sprockets by using the `depend_on`or `depend_on_directory`directive. Rails
535
+
implements the above feature by auto calling `depend_on` on the original asset
0 commit comments