sprockets 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +68 -0
  3. data/README.md +397 -408
  4. data/bin/sprockets +12 -7
  5. data/lib/rake/sprocketstask.rb +3 -2
  6. data/lib/sprockets/add_source_map_comment_to_asset_processor.rb +60 -0
  7. data/lib/sprockets/asset.rb +19 -23
  8. data/lib/sprockets/autoload/babel.rb +8 -0
  9. data/lib/sprockets/autoload/closure.rb +1 -0
  10. data/lib/sprockets/autoload/coffee_script.rb +1 -0
  11. data/lib/sprockets/autoload/eco.rb +1 -0
  12. data/lib/sprockets/autoload/ejs.rb +1 -0
  13. data/lib/sprockets/autoload/jsminc.rb +8 -0
  14. data/lib/sprockets/autoload/sass.rb +1 -0
  15. data/lib/sprockets/autoload/sassc.rb +8 -0
  16. data/lib/sprockets/autoload/uglifier.rb +1 -0
  17. data/lib/sprockets/autoload/yui.rb +1 -0
  18. data/lib/sprockets/autoload/zopfli.rb +7 -0
  19. data/lib/sprockets/autoload.rb +5 -0
  20. data/lib/sprockets/babel_processor.rb +66 -0
  21. data/lib/sprockets/base.rb +59 -11
  22. data/lib/sprockets/bower.rb +5 -2
  23. data/lib/sprockets/bundle.rb +44 -4
  24. data/lib/sprockets/cache/file_store.rb +32 -7
  25. data/lib/sprockets/cache/memory_store.rb +9 -0
  26. data/lib/sprockets/cache/null_store.rb +8 -0
  27. data/lib/sprockets/cache.rb +42 -5
  28. data/lib/sprockets/cached_environment.rb +14 -19
  29. data/lib/sprockets/closure_compressor.rb +6 -11
  30. data/lib/sprockets/coffee_script_processor.rb +19 -5
  31. data/lib/sprockets/compressing.rb +62 -2
  32. data/lib/sprockets/configuration.rb +3 -7
  33. data/lib/sprockets/context.rb +98 -23
  34. data/lib/sprockets/dependencies.rb +9 -8
  35. data/lib/sprockets/digest_utils.rb +104 -60
  36. data/lib/sprockets/directive_processor.rb +45 -35
  37. data/lib/sprockets/eco_processor.rb +3 -2
  38. data/lib/sprockets/ejs_processor.rb +3 -2
  39. data/lib/sprockets/encoding_utils.rb +8 -4
  40. data/lib/sprockets/environment.rb +9 -4
  41. data/lib/sprockets/erb_processor.rb +28 -21
  42. data/lib/sprockets/errors.rb +1 -1
  43. data/lib/sprockets/exporters/base.rb +72 -0
  44. data/lib/sprockets/exporters/file_exporter.rb +24 -0
  45. data/lib/sprockets/exporters/zlib_exporter.rb +33 -0
  46. data/lib/sprockets/exporters/zopfli_exporter.rb +14 -0
  47. data/lib/sprockets/exporting.rb +73 -0
  48. data/lib/sprockets/file_reader.rb +1 -0
  49. data/lib/sprockets/http_utils.rb +26 -6
  50. data/lib/sprockets/jsminc_compressor.rb +32 -0
  51. data/lib/sprockets/jst_processor.rb +11 -10
  52. data/lib/sprockets/loader.rb +236 -69
  53. data/lib/sprockets/manifest.rb +97 -44
  54. data/lib/sprockets/manifest_utils.rb +9 -6
  55. data/lib/sprockets/mime.rb +8 -42
  56. data/lib/sprockets/npm.rb +52 -0
  57. data/lib/sprockets/path_dependency_utils.rb +3 -11
  58. data/lib/sprockets/path_digest_utils.rb +2 -1
  59. data/lib/sprockets/path_utils.rb +106 -21
  60. data/lib/sprockets/paths.rb +1 -0
  61. data/lib/sprockets/preprocessors/default_source_map.rb +49 -0
  62. data/lib/sprockets/processing.rb +31 -51
  63. data/lib/sprockets/processor_utils.rb +81 -15
  64. data/lib/sprockets/resolve.rb +182 -95
  65. data/lib/sprockets/sass_cache_store.rb +1 -0
  66. data/lib/sprockets/sass_compressor.rb +21 -17
  67. data/lib/sprockets/sass_functions.rb +1 -0
  68. data/lib/sprockets/sass_importer.rb +1 -0
  69. data/lib/sprockets/sass_processor.rb +45 -17
  70. data/lib/sprockets/sassc_compressor.rb +56 -0
  71. data/lib/sprockets/sassc_processor.rb +297 -0
  72. data/lib/sprockets/server.rb +57 -34
  73. data/lib/sprockets/source_map_processor.rb +66 -0
  74. data/lib/sprockets/source_map_utils.rb +483 -0
  75. data/lib/sprockets/transformers.rb +63 -35
  76. data/lib/sprockets/uglifier_compressor.rb +23 -20
  77. data/lib/sprockets/unloaded_asset.rb +139 -0
  78. data/lib/sprockets/uri_tar.rb +99 -0
  79. data/lib/sprockets/uri_utils.rb +15 -14
  80. data/lib/sprockets/utils/gzip.rb +99 -0
  81. data/lib/sprockets/utils.rb +43 -59
  82. data/lib/sprockets/version.rb +2 -1
  83. data/lib/sprockets/yui_compressor.rb +5 -14
  84. data/lib/sprockets.rb +103 -33
  85. metadata +151 -22
  86. data/LICENSE +0 -21
  87. data/lib/sprockets/coffee_script_template.rb +0 -6
  88. data/lib/sprockets/eco_template.rb +0 -6
  89. data/lib/sprockets/ejs_template.rb +0 -6
  90. data/lib/sprockets/engines.rb +0 -81
  91. data/lib/sprockets/erb_template.rb +0 -6
  92. data/lib/sprockets/legacy.rb +0 -314
  93. data/lib/sprockets/legacy_proc_processor.rb +0 -35
  94. data/lib/sprockets/legacy_tilt_processor.rb +0 -29
  95. data/lib/sprockets/sass_template.rb +0 -7
data/README.md CHANGED
@@ -5,7 +5,6 @@ It features declarative dependency management for JavaScript and CSS
5
5
  assets, as well as a powerful preprocessor pipeline that allows you to
6
6
  write assets in languages like CoffeeScript, Sass and SCSS.
7
7
 
8
-
9
8
  ## Installation
10
9
 
11
10
  Install Sprockets from RubyGems:
@@ -17,62 +16,37 @@ $ gem install sprockets
17
16
  Or include it in your project's `Gemfile` with Bundler:
18
17
 
19
18
  ``` ruby
20
- gem 'sprockets', '~> 3.0'
19
+ gem 'sprockets', '~> 4.0'
21
20
  ```
22
21
 
22
+ ## Upgrading to Sprockets 4.x
23
23
 
24
- ## Understanding the Sprockets Environment
25
-
26
- You'll need an instance of the `Sprockets::Environment` class to
27
- access and serve assets from your application. Under Rails 4.0 and
28
- later, `YourApp::Application.assets` is a preconfigured
29
- `Sprockets::Environment` instance. For Rack-based applications, create
30
- an instance in `config.ru`.
31
-
32
- The Sprockets `Environment` has methods for retrieving and serving
33
- assets, manipulating the load path, and registering processors. It is
34
- also a Rack application that can be mounted at a URL to serve assets
35
- over HTTP.
24
+ These are the major features in Sprockets 4.x
36
25
 
37
- ### The Load Path
26
+ - Source Maps
27
+ - Manifest.js
28
+ - ES6 support
29
+ - Deprecated processor interface in 3.x is removed in 4.x
38
30
 
39
- The *load path* is an ordered list of directories that Sprockets uses
40
- to search for assets.
31
+ Read more about them by referencing [Upgrading document](UPGRADING.md)
41
32
 
42
- In the simplest case, a Sprockets environment's load path will consist
43
- of a single directory containing your application's asset source
44
- files. When mounted, the environment will serve assets from this
45
- directory as if they were static files in your public root.
33
+ ## Guides
46
34
 
47
- The power of the load path is that it lets you organize your source
48
- files into multiple directories -- even directories that live outside
49
- your application -- and combine those directories into a single
50
- virtual filesystem. That means you can easily bundle JavaScript, CSS
51
- and images into a Ruby library or [Bower](http://bower.io) package and import them into your application.
35
+ For most people interested in using Sprockets, you will want to see the README below.
52
36
 
53
- #### Manipulating the Load Path
37
+ If you are a framework developer that is using Sprockets, see [Building an Asset Processing Framework](guides/building_an_asset_processing_framework.md).
54
38
 
55
- To add a directory to your environment's load path, use the
56
- `append_path` and `prepend_path` methods. Directories at the beginning
57
- of the load path have precedence over subsequent directories.
39
+ If you are a library developer who is extending the functionality of Sprockets, see [Extending Sprockets](guides/extending_sprockets.md).
58
40
 
59
- ``` ruby
60
- environment = Sprockets::Environment.new
61
- environment.append_path 'app/assets/javascripts'
62
- environment.append_path 'lib/assets/javascripts'
63
- environment.append_path 'vendor/assets/bower_components'
64
- ```
41
+ If you want to work on Sprockets or better understand how it works read [How Sprockets Works](guides/how_sprockets_works.md)
65
42
 
66
- In general, you should append to the path by default and reserve
67
- prepending for cases where you need to override existing assets.
43
+ ## Behavior Overview
68
44
 
69
- ### Accessing Assets
45
+ You can interact with Sprockets primarily through directives and file extensions. This section covers how to use each of these things, and the defaults that ship with Sprockets.
70
46
 
71
- Once you've set up your environment's load path, you can mount the
72
- environment as a Rack server and request assets via HTTP. You can also
73
- access assets programmatically from within your application.
47
+ Since you are likely using Sprockets through another framework (such as the [the Rails asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html)), there will be configuration options you can toggle that will change behavior such as what directories or files get compiled. For that documentation you should see your framework's documentation.
74
48
 
75
- #### Logical Paths
49
+ #### Accessing Assets
76
50
 
77
51
  Assets in Sprockets are always referenced by their *logical path*.
78
52
 
@@ -82,562 +56,577 @@ contains the directory `app/assets/javascripts`:
82
56
 
83
57
  <table>
84
58
  <tr>
85
- <th>Asset source file</th>
86
59
  <th>Logical path</th>
60
+ <th>Source file on disk</th>
87
61
  </tr>
88
62
  <tr>
89
- <td>app/assets/javascripts/application.js</td>
90
63
  <td>application.js</td>
64
+ <td>app/assets/javascripts/application.js</td>
91
65
  </tr>
92
66
  <tr>
93
- <td>app/assets/javascripts/models/project.js</td>
94
67
  <td>models/project.js</td>
68
+ <td>app/assets/javascripts/models/project.js</td>
69
+ </tr>
70
+ <tr>
71
+ <td>hello.js</td>
72
+ <td>app/assets/javascripts/hello.coffee</td>
95
73
  </tr>
96
74
  </table>
97
75
 
98
- In this way, all directories in the load path are merged to create a
99
- virtual filesystem whose entries are logical paths.
76
+ > Note: For assets that are compiled or transpiled, you want to specify the extension that you want, not the extension on disk. For example we specified `hello.js` even if the file on disk is a coffeescript file, since the asset it will generate is javascript.
100
77
 
101
- #### Serving Assets Over HTTP
78
+ ### Directives
102
79
 
103
- When you mount an environment, all of its assets are accessible as
104
- logical paths underneath the *mount point*. For example, if you mount
105
- your environment at `/assets` and request the URL
106
- `/assets/application.js`, Sprockets will search your load path for the
107
- file named `application.js` and serve it.
80
+ Directives are special comments in your asset file and the main way of interacting with processors. What kind of interactions? You can use these directives to tell Sprockets to load other files, or specify dependencies on other assets.
108
81
 
109
- Under Rails 4.0 and later, your Sprockets environment is automatically
110
- mounted at `/assets`. If you are using Sprockets with a Rack
111
- application, you will need to mount the environment yourself. A good
112
- way to do this is with the `map` method in `config.ru`:
82
+ For example, let's say you have custom JavaScript that you've written. You put this javascript in a file called `beta.js`. The javascript makes heavy use of jQuery, so you need to load that before your code executes. You could add a `require` directive to the top of `beta.js`:
113
83
 
114
- ``` ruby
115
- require 'sprockets'
116
- map '/assets' do
117
- environment = Sprockets::Environment.new
118
- environment.append_path 'app/assets/javascripts'
119
- environment.append_path 'app/assets/stylesheets'
120
- run environment
121
- end
84
+ ```js
85
+ //= require jquery
122
86
 
123
- map '/' do
124
- run YourRackApp
125
- end
87
+ $().ready({
88
+ // my custom code here
89
+ })
126
90
  ```
127
91
 
128
- #### Accessing Assets Programmatically
92
+ The directive processor understands comment blocks in three formats:
129
93
 
130
- You can use the `find_asset` method (aliased as `[]`) to retrieve an
131
- asset from a Sprockets environment. Pass it a logical path and you'll
132
- get a `Sprockets::Asset` instance back:
94
+ ``` css
95
+ /* Multi-line comment blocks (CSS, SCSS, JavaScript)
96
+ *= require foo
97
+ */
98
+ ```
133
99
 
134
- ``` ruby
135
- environment['application.js']
136
- # => #<Sprockets::Asset ...>
100
+ ``` js
101
+ // Single-line comment blocks (SCSS, JavaScript)
102
+ //= require foo
103
+ ```
104
+
105
+ ``` coffee
106
+ # Single-line comment blocks (CoffeeScript)
107
+ #= require foo
137
108
  ```
138
109
 
139
- Call `to_s` on the resulting asset to access its contents, `length` to
140
- get its length in bytes, `mtime` to query its last-modified time, and
141
- `filename` to get its full path on the filesystem.
110
+ > Note: Directives are only processed if they come before any application code. Once you have a line that does not include a comment or whitespace then Sprockets will stop looking for directives. If you use a directive outside of the "header" of the document it will not do anything, and won't raise any errors.
142
111
 
112
+ Here is a list of the available directives:
143
113
 
144
- ## Using Processors
114
+ - [`require`](#require) - Add the contents of a file to current
115
+ - [`require_self`](#require_self) - Change order of where current contents are concatenated to current
116
+ - [`require_directory`](#require_directory) - Add contents of each file in a folder to current
117
+ - [`require_tree`](#require_tree) - Add contents of all files in all directories in a path to current
118
+ - [`link`](#link) - Make target file compile and be publically available without adding contents to current
119
+ - [`link_directory`](#link_directory) - Make target directory compile and be publically available without adding contents to current
120
+ - [`link_tree`](#link_tree) - Make target tree compile and be publically available without adding contents to current
121
+ - [`depend_on`](#depend_on) - Recompile current file if target has changed
122
+ - [`stub`](#stub) - Ignore target file
145
123
 
146
- Asset source files can be written in another format, like SCSS or
147
- CoffeeScript, and automatically compiled to CSS or JavaScript by
148
- Sprockets. Processors that convert a file from one format to another are called *transformers*.
124
+ You can see what each of these does below.
149
125
 
150
- ### Minifying Assets
126
+ ### Specifying Processors through File Extensions
151
127
 
152
- Several JavaScript and CSS minifiers are available through shorthand.
128
+ Sprockets uses the filename extensions to determine what processors to run on your file and in what order. For example if you have a file:
153
129
 
154
- ``` ruby
155
- environment.js_compressor = :uglify
156
- environment.css_compressor = :scss
130
+ ```
131
+ application.scss
157
132
  ```
158
133
 
159
- ### Styling with Sass and SCSS
134
+ Then Sprockets will by default run the sass processor (which implements scss). The output file will be converted to css.
160
135
 
161
- [Sass](http://sass-lang.com/) is a language that compiles to CSS and
162
- adds features like nested rules, variables, mixins and selector
163
- inheritance.
136
+ You can specify multiple processors by specifying multiple file extensions. For example you can use Ruby's [ERB template language](#invoking-ruby-with-erb) to embed content in your doc before running the sass processor. To accomplish this you would need to name your file
164
137
 
165
- If the `sass` gem is available to your application, you can use Sass
166
- to write CSS assets in Sprockets.
138
+ ```
139
+ application.scss.erb
140
+ ```
167
141
 
168
- Sprockets supports both Sass syntaxes. For the original
169
- whitespace-sensitive syntax, use the extension `.sass`. For the
170
- new SCSS syntax, use the extension `.scss`.
142
+ Processors are run from right to left (tail to head), so in the above example the processor associated with `erb` will be run before the processor associated with `scss` extension.
171
143
 
172
- ### Scripting with CoffeeScript
144
+ For a description of the processors that Sprockets has by default see the "default processors" section below. Other libraries may register additional processors.
173
145
 
174
- [CoffeeScript](http://jashkenas.github.com/coffee-script/) is a
175
- language that compiles to the "good parts" of JavaScript, featuring a
176
- cleaner syntax with array comprehensions, classes, and function
177
- binding.
146
+ When "asking" for a compiled file, you always ask for the extension you want. For example if you're using Rails, to get the contents of `application.scss.erb` you would use
178
147
 
179
- If the `coffee-script` gem is available to your application, you can
180
- use CoffeeScript to write JavaScript assets in Sprockets. Note that
181
- the CoffeeScript compiler is written in JavaScript, and you will need
182
- an [ExecJS](https://github.com/rails/execjs)-supported runtime
183
- on your system to invoke it.
148
+ ```
149
+ asset_path("application.css")
150
+ ```
184
151
 
185
- To write JavaScript assets with CoffeeScript, use the extension
186
- `.coffee`.
152
+ Sprockets understands that `application.scss.erb` will compile down to a `application.css`. Ask for what you need, not what you have.
187
153
 
188
- ### JavaScript Templating with EJS and Eco
154
+ If this isn't working like you expect, make sure you didn't typo an extension, and make sure the file is on a "load path" (see framework docs for adding new load paths).
189
155
 
190
- Sprockets supports *JavaScript templates* for client-side rendering of
191
- strings or markup. JavaScript templates have the special format
192
- extension `.jst` and are compiled to JavaScript functions.
156
+ ## File Order Processing
193
157
 
194
- When loaded, a JavaScript template function can be accessed by its
195
- logical path as a property on the global `JST` object. Invoke a
196
- template function to render the template as a string. The resulting
197
- string can then be inserted into the DOM.
158
+ By default files are processed in alphabetical order. This behavior can impact your asset compilation when one asset needs to be loaded before another.
159
+
160
+ For example if you have an `application.js` and it loads another directory
198
161
 
162
+ ```js
163
+ //= require_directory my_javascript
199
164
  ```
200
- <!-- templates/hello.jst.ejs -->
201
- <div>Hello, <span><%= name %></span>!</div>
202
165
 
203
- // application.js
204
- //= require templates/hello
205
- $("#hello").html(JST["templates/hello"]({ name: "Sam" }));
166
+ The files in that directory will be loaded in alphabetical order. If the directory looks like this:
167
+
168
+ ```sh
169
+ $ ls -1 my_javascript/
170
+
171
+ alpha.js
172
+ beta.js
173
+ jquery.js
206
174
  ```
207
175
 
208
- Sprockets supports two JavaScript template languages:
209
- [EJS](https://github.com/sstephenson/ruby-ejs), for embedded
210
- JavaScript, and [Eco](https://github.com/sstephenson/ruby-eco), for
211
- embedded CoffeeScript. Both languages use the familiar `<% … %>`
212
- syntax for embedding logic in templates.
176
+ Then `alpha.js` will be loaded before either of the other two. This can be a problem if `alpha.js` uses jquery. For this reason it is not recommend to use `require_directory` with files that are ordering dependent. You can either require individual files manually:
213
177
 
214
- If the `ejs` gem is available to your application, you can use EJS
215
- templates in Sprockets. EJS templates have the extension `.jst.ejs`.
178
+ ```js
179
+ //= require jquery
180
+ //= require alpha
181
+ //= require beta
182
+ ```
216
183
 
217
- If the `eco` gem is available to your application, you can use [Eco
218
- templates](https://github.com/sstephenson/eco) in Sprockets. Eco
219
- templates have the extension `.jst.eco`. Note that the `eco` gem
220
- depends on the CoffeeScript compiler, so the same caveats apply as
221
- outlined above for the CoffeeScript engine.
184
+ Or you can use index files to proxy your folders.
222
185
 
223
- ### Invoking Ruby with ERB
186
+ ### Index files are proxies for folders
224
187
 
225
- Sprockets provides an ERB engine for preprocessing assets using
226
- embedded Ruby code. Append `.erb` to a CSS or JavaScript asset's
227
- filename to enable the ERB engine.
188
+ In Sprockets index files such as `index.js` or `index.css` files inside of a folder will generate a file with the folder's name. So if you have a `foo/index.js` file it will compile down to `foo.js`. This is similar to NPM's behavior of using [folders as modules](https://nodejs.org/api/modules.html#modules_folders_as_modules). It is also somewhat similar to the way that a file in `public/my_folder/index.html` can be reached by a request to `/my_folder`. This means that you cannot directly use an index file. For example this would not work:
228
189
 
229
- Ruby code embedded in an asset is evaluated in the context of a
230
- `Sprockets::Context` instance for the given asset. Common uses for ERB
231
- include:
190
+ ```erb
191
+ <%= asset_path("foo/index.js") %>
192
+ ```
232
193
 
233
- - embedding another asset as a Base64-encoded `data:` URI with the
234
- `asset_data_uri` helper
235
- - inserting the URL to another asset, such as with the `asset_path`
236
- helper provided by the Sprockets Rails plugin
237
- - embedding other application resources, such as a localized string
238
- database, in a JavaScript asset via JSON
239
- - embedding version constants loaded from another file
194
+ Instead you would need to use:
240
195
 
241
- See the [Helper Methods](lib/sprockets/context.rb) section for more information about
242
- interacting with `Sprockets::Context` instances via ERB.
196
+ ```erb
197
+ <%= asset_path("foo.js") %>
198
+ ```
243
199
 
200
+ Why would you want to use this behavior? It is common behavior where you might want to include an entire directory of files in a top level JavaScript. You can do this in Sprockets using `require_tree .`
244
201
 
245
- ## Managing and Bundling Dependencies
202
+ ```js
203
+ //= require_tree .
204
+ ```
246
205
 
247
- You can create *asset bundles* -- ordered concatenations of asset
248
- source files -- by specifying dependencies in a special comment syntax
249
- at the top of each source file.
206
+ This has the problem that files are required alphabetically. If your directory has `jquery-ui.js` and `jquery.min.js` then Sprockets will require `jquery-ui.js` before `jquery` is required which won't work (because jquery-ui depends on jquery). Previously the only way to get the correct ordering would be to rename your files, something like `0-jquery-ui.js`. Instead of doing that you can use an index file.
250
207
 
251
- Sprockets reads these comments, called *directives*, and processes
252
- them to recursively build a dependency graph. When you request an
253
- asset with dependencies, the dependencies will be included in order at
254
- the top of the file.
208
+ For example, if you have an `application.js` and want all the files in the `foo/` folder you could do this:
255
209
 
256
- ### The Directive Processor
210
+ ```js
211
+ //= require foo.js
212
+ ```
257
213
 
258
- Sprockets runs the *directive processor* on each CSS and JavaScript
259
- source file. The directive processor scans for comment lines beginning
260
- with `=` in comment blocks at the top of the file.
214
+ Then create a file `foo/index.js` that requires all the files in that folder in any order you want using relative references:
261
215
 
262
- ``` js
263
- //= require jquery
264
- //= require jquery-ui
265
- //= require backbone
266
- //= require_tree .
216
+ ```js
217
+ //= require ./foo.min.js
218
+ //= require ./foo-ui.js
267
219
  ```
268
220
 
269
- The first word immediately following `=` specifies the directive
270
- name. Any words following the directive name are treated as
271
- arguments. Arguments may be placed in single or double quotes if they
272
- contain spaces, similar to commands in the Unix shell.
221
+ Now in your `application.js` will correctly load the `foo.min.js` before `foo-ui.js`. If you used `require_tree` it would not work correctly.
273
222
 
274
- **Note**: Non-directive comment lines will be preserved in the final
275
- asset, but directive comments are stripped after
276
- processing. Sprockets will not look for directives in comment blocks
277
- that occur after the first line of code.
223
+ ## Cache
278
224
 
279
- #### Supported Comment Types
225
+ Compiling assets is slow. It requires a lot of disk use to pull assets off of hard drives, a lot of RAM to manipulate those files in memory, and a lot of CPU for compilation operations. Because of this Sprockets has a cache to speed up asset compilation times. That's the good news. The bad news, is that sprockets has a cache and if you've found a bug it's likely going to involve the cache.
280
226
 
281
- The directive processor understands comment blocks in three formats:
227
+ By default Sprockets uses the file system to cache assets. It makes sense that Sprockets does not want to generate assets that already exist on disk in `public/assets`, what might not be as intuitive is that Sprockets needs to cache "partial" assets.
282
228
 
283
- ``` css
284
- /* Multi-line comment blocks (CSS, SCSS, JavaScript)
285
- *= require foo
286
- */
229
+ For example if you have an `application.js` and it is made up of `a.js`, `b.js`, all the way to `z.js`
230
+
231
+ ```js
232
+ //= require a.js
233
+ //= require b.js
234
+ # ...
235
+ //= require z.js
287
236
  ```
288
237
 
289
- ``` js
290
- // Single-line comment blocks (SCSS, JavaScript)
291
- //= require foo
238
+ The first time this file is compiled the `application.js` output will be written to disk, but also intermediary compiled files for `a.js` etc. will be written to the cache directory (usually `tmp/cache/assets`).
239
+
240
+ 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
+ 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
+
244
+ On Rails you can force a "clean" install by clearing the `public/assets` and `tmp/cache/assets` directories.
245
+
246
+
247
+ ## Default Directives
248
+
249
+ Directives take a path or a path to a file. Paths for directive can be relative to the current file, for example:
250
+
251
+ ```js
252
+ //= require ../foo.js
292
253
  ```
293
254
 
294
- ``` coffee
295
- # Single-line comment blocks (CoffeeScript)
296
- #= require foo
255
+ This would load the file up one directory and named `foo.js`. However this isn't required if `foo.js` is on one of Sprocket's load paths. You can simply use
256
+
257
+ ```js
258
+ //= require foo.js
297
259
  ```
298
260
 
299
- ### Sprockets Directives
261
+ Without any prepended dots and sprockets will search for the asset. If the asset is on a sub-path of the load path, you can specify it without using a relative path as well:
262
+
263
+ ```js
264
+ //= require sub/path/foo.js
265
+ ```
300
266
 
301
- You can use the following directives to declare dependencies in asset
302
- source files.
267
+ You can also use an absolute path, but this is discouraged unless you know the directory structure of every machine you plan on running code on.
303
268
 
304
- For directives that take a *path* argument, you may specify either a
305
- logical path or a relative path. Relative paths begin with `./` and
306
- reference files relative to the location of the current file.
269
+ Below is a section for each of the built in directive types supported by Sprockets.
307
270
 
308
- #### The `require` Directive
271
+ ### require
309
272
 
310
273
  `require` *path* inserts the contents of the asset source file
311
274
  specified by *path*. If the file is required multiple times, it will
312
275
  appear in the bundle only once.
313
276
 
314
- ### The `require_directory` Directive ###
277
+ **Example:**
315
278
 
316
- `require_directory` *path* requires all source files of the same
317
- format in the directory specified by *path*. Files are required in
318
- alphabetical order.
279
+ If you've got an `a.js`:
319
280
 
320
- #### The `require_tree` Directive
281
+ ```js
282
+ var a = "A";
283
+ ```
321
284
 
322
- `require_tree` *path* works like `require_directory`, but operates
323
- recursively to require all files in all subdirectories of the
324
- directory specified by *path*.
285
+ and a `b.js`;
325
286
 
326
- #### The `require_self` Directive
287
+ ```js
288
+ var b = "B";
289
+ ```
290
+
291
+ Then you could require both of these in an `application.js`
292
+
293
+ ```js
294
+ //= require a.js
295
+ //= require b.js
296
+ ```
297
+
298
+ Which would generate one concatenated file:
299
+
300
+ ```js
301
+ var a = "A";
302
+ var b = "B";
303
+ ```
304
+
305
+ ### require_self
327
306
 
328
307
  `require_self` tells Sprockets to insert the body of the current
329
308
  source file before any subsequent `require` directives.
330
309
 
331
- #### The `link` Directive
310
+ **Example:**
332
311
 
333
- `link` *path* declares a dependency on the target *path* and adds it to a list
334
- of subdependencies to automatically be compiled when the asset is written out to
335
- disk.
336
-
337
- For an example, in a CSS file you might reference an external image that always
338
- needs to be compiled along with the css file.
312
+ If you've got an `a.js`:
339
313
 
340
- ``` css
341
- /*= link "logo.png" */
342
- .logo {
343
- background-image: url(logo.png)
344
- }
314
+ ```js
315
+ var a = "A";
345
316
  ```
346
317
 
347
- However, if you use a `asset-path` or `asset-url` SCSS helper, these links will
348
- automatically be defined for you.
318
+ And an `application.js`
349
319
 
350
- ``` css
351
- .logo {
352
- background-image: asset-url("logo.png")
353
- }
320
+ ```js
321
+ //= require_self
322
+ //= require 'a.js'
323
+
324
+ var app_name = "Sprockets";
354
325
  ```
355
326
 
356
- #### The `depend_on` Directive
327
+ Then this will take the contents of `application.js` (that come after the last require) and put them at the beginning of the file:
357
328
 
358
- `depend_on` *path* declares a dependency on the given *path* without
359
- including it in the bundle. This is useful when you need to expire an
360
- asset's cache in response to a change in another file.
329
+ ```js
330
+ var app_name = "Sprockets";
331
+ var a = "A";
332
+ ```
361
333
 
362
- #### The `depend_on_asset` Directive
334
+ ### require_directory
363
335
 
364
- `depend_on_asset` *path* works like `depend_on`, but operates
365
- 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`.
336
+ `require_directory` *path* requires all source files of the same
337
+ format in the directory specified by *path*. Files are required in
338
+ alphabetical order.
366
339
 
367
- #### The `stub` Directive
340
+ **Example:**
368
341
 
369
- `stub` *path* allows dependency to be excluded from the asset bundle.
370
- The *path* must be a valid asset and may or may not already be part
371
- of the bundle. `stub` should only be used at the top level bundle, not
372
- within any subdependencies.
342
+ If we've got a directory called `alphabet` with an `a.js` and `b.js` files like before, then our `application.js`
373
343
 
344
+ ```js
345
+ //= require_directory alphabet
346
+ ```
374
347
 
375
- ## Processor Interface
348
+ Would produce:
376
349
 
377
- Sprockets 2.x was originally design around [Tilt](https://github.com/rtomayko/tilt)'s engine interface. However, starting with 3.x, a new interface has been introduced deprecating Tilt.
350
+ ```js
351
+ var a = "A";
352
+ var b = "B";
353
+ ```
378
354
 
379
- Similar to Rack, a processor is a any "callable" (an object that responds to `call`). This maybe a simple Proc or a full class that defines a `def self.call(input)` method. The `call` method accepts an `input` Hash and returns a Hash of metadata.
355
+ 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.
380
356
 
381
- Also see [`Sprockets::ProcessorUtils`](https://github.com/rails/sprockets/blob/master/lib/sprockets/processor_utils.rb) for public helper methods.
357
+ ### require_tree
382
358
 
383
- ### input Hash
359
+ `require_tree` *path* works like `require_directory`, but operates
360
+ recursively to require all files in all subdirectories of the
361
+ directory specified by *path*.
384
362
 
385
- The `input` Hash defines the following public fields.
363
+ ### link
386
364
 
387
- * `:data` - String asset contents
388
- * `:environment` - Current `Sprockets::Environment` instance.
389
- * `:cache` - A `Sprockets::Cache` instance. See [`Sprockets::Cache#fetch`](https://github.com/rails/sprockets/blob/master/lib/sprockets/cache.rb).
390
- * `:uri` - String Asset URI.
391
- * `:filename` - String full path to original file.
392
- * `:load_path` - String current load path for filename.
393
- * `:name` - String logical path for filename.
394
- * `:content_type` - String content type of the output asset.
395
- * `:metadata` - Hash of processor metadata.
365
+ `link` *path* declares a dependency on the target *path* and adds it to a list
366
+ of subdependencies to automatically be compiled when the asset is written out to
367
+ disk.
396
368
 
397
- ``` ruby
398
- def self.call(input)
399
- input[:cache].fetch("my:cache:key:v1") do
400
- # Remove all semicolons from source
401
- input[:data].gsub(";", "")
402
- end
403
- end
404
- ```
369
+ Example:
405
370
 
406
- ### return Hash
371
+ If you've got a `manifest.js` file and you want to explicitly make sure an `admin.js` file is
372
+ generated and made available to the public you can link it like this:
407
373
 
408
- The processor should return metadata `Hash`. With the exception of the `:data` key, the processor can store arbitrary JSON valid values in this Hash. The data will be stored and exposed on `Asset#metadata`.
374
+ ```
375
+ //= link admin.js
376
+ ```
409
377
 
410
- The returned `:data` replaces the assets `input[:data]` to the next processor in the chain. Returning a `String` is shorthand for returning `{ data: str }`. And returning `nil` is shorthand for a no-op where the input data is not transformed, `{ data: input[:data] }`.
378
+ ### link_directory
411
379
 
412
- ### metadata
380
+ `link_directory` *path* links all the files inside the directory specified by the *path*
413
381
 
414
- The metadata Hash provides an open format for processors to extend the pipeline processor. Internally, built-in processors use it for passing data to each other.
382
+ ### link_tree
415
383
 
416
- * `:required` - A `Set` of String Asset URIs that the Bundle processor should concatenate together.
417
- * `:stubbed` - A `Set` of String Asset URIs that will be omitted from the `:required` set.
418
- * `:links` - A `Set` of String Asset URIs that should be compiled along with this asset.
419
- * `:dependencies` - A `Set` of String Cache URIs that should be monitored for caching.
384
+ `link_tree` *path* works like `link_directory`, but operates
385
+ recursively to link all files in all subdirectories of the
386
+ directory specified by *path*.
420
387
 
421
- ``` ruby
422
- def self.call(input)
423
- # Any metadata may start off as nil, so initialize it the value
424
- required = Set.new(input[:metadata][:required])
388
+ Example:
425
389
 
426
- # Manually add "foo.js" asset uri to our bundle
427
- required << input[:environment].resolve("foo.js")
390
+ You can specify a file extension so any extra files will be ignored:
428
391
 
429
- { required: required }
430
- end
392
+ ```js
393
+ //= link_tree ./path/to/folder .js
431
394
  ```
432
395
 
396
+ > Note: There is an intentional space between the path and the extension
433
397
 
434
- ## Development
398
+ ### depend_on
435
399
 
436
- ### Contributing
400
+ `depend_on` *path* declares a dependency on the given *path* without
401
+ including it in the bundle. This is useful when you need to expire an
402
+ asset's cache in response to a change in another file.
437
403
 
438
- The Sprockets source code is [hosted on
439
- GitHub](https://github.com/rails/sprockets). You can check out a
440
- copy of the latest code using Git:
404
+ **Example:**
441
405
 
442
- $ git clone https://github.com/rails/sprockets
406
+ If you have a file such as `bar.data` and you're using data from that file in another file, then
407
+ you need to tell sprockets that it needs to re-compile the file if `bar.data` changes:
443
408
 
444
- If you've found a bug or have a question, please open an issue on the
445
- [Sprockets issue
446
- tracker](https://github.com/rails/sprockets/issues). Or, clone
447
- the Sprockets repository, write a failing test case, fix the bug and
448
- submit a pull request.
409
+ ```js
410
+ //= depend_on "bar.data"
449
411
 
450
- ### Version History
412
+ var bar = '<%= File.read("bar.data") %>'
413
+ ```
451
414
 
452
- **3.0.0**
415
+ ### depend_on_asset
453
416
 
454
- * New processor API. Tilt interface is deprecated.
455
- * Improved file store caching backend.
456
- * MIME Types now accept charset custom charset detecters. Improves support for UTF-16/32 files.
457
- * Environment#version no longer affects asset digests. Only used for busting the asset cache.
458
- * Removed builtin support for LESS.
459
- * Removed `//= include` directive support.
460
- * Deprecated `BundledAsset#to_a`. Use `BundledAsset#included` to access debugging subcomponents.
461
- * Support circular dependencies. For parity with ES6 modules.
462
- * Manifest compilation will no longer generate .gz files by default. [Mixing
463
- Content-Encoding and ETags is just a bad
464
- idea](https://issues.apache.org/bugzilla/show_bug.cgi?id=39727)
465
- * Added linked or referenced assets. When an asset is compiled, any of its links will be compiled as well.
466
- * Introduce some limitations around enumerating all logical paths. 4.x will deprecate it and favor linked manifests for compliation.
467
- * Add Asset integrity attribute for Subresource Integrity
468
- * Default digest changed to SHA256. Configuring `digest_class` is deprecated.
469
- * Rename `Asset#digest` to `Asset#hexdigest`. `Asset#digest` is deprecated and will
470
- return a raw byte String in 4.x.
471
- * Added transitional compatibility flag to `Environment#resolve(path, compat: true)`. 2.x mode operates with `compat: true` and 4.x with `compat: false`
472
- * `manifest-abc123.json` renamed to `.sprockets-abc123.json`
417
+ `depend_on_asset` *path* works like `depend_on`, but operates
418
+ 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`.
473
419
 
474
- **2.12.3** (October 28, 2014)
420
+ ### stub
475
421
 
476
- * Security: Fix directory traversal bug in development mode server.
422
+ `stub` *path* excludes that asset and its dependencies from the asset bundle.
423
+ The *path* must be a valid asset and may or may not already be part
424
+ of the bundle. `stub` should only be used at the top level bundle, not
425
+ within any subdependencies.
477
426
 
478
- **2.12.2** (September 5, 2014)
427
+ ### Invoking Ruby with ERB
479
428
 
480
- * Ensure internal asset lookups calls are still restricted to load paths within
481
- asset compiles. Though, you should not depend on internal asset resolves to be
482
- completely restricted for security reasons. Assets themselves should be
483
- considered full scripting environments with filesystem access.
429
+ Sprockets provides an ERB engine for preprocessing assets using
430
+ embedded Ruby code. Append `.erb` to a CSS or JavaScript asset's
431
+ filename to enable the ERB engine.
484
432
 
485
- **2.12.1** (April 17, 2014)
433
+ For example if you have an `app/application/javascripts/app_name.js.erb`
434
+ you could have this in the template
486
435
 
487
- * Fix making manifest target directory when its different than the output directory.
436
+ ```js
437
+ var app_name = "<%= ENV['APP_NAME'] %>";
438
+ ```
488
439
 
489
- **2.12.0** (March 13, 2014)
440
+ Generated files are cached. If you're using an `ENV` var then
441
+ when you change then ENV var the asset will be forced to
442
+ recompile. This behavior is only true for environment variables,
443
+ if you are pulling a value from somewhere else, such as a database,
444
+ must manually invalidate the cache to see the change.
490
445
 
491
- * Avoid context reference in SassImporter hack so its Marshallable. Fixes
492
- issues with Sass 3.3.x.
446
+ If you're using Rails, there are helpers you can use such as `asset_url`
447
+ that will cause a recompile if the value changes.
493
448
 
494
- **2.11.0** (February 19, 2014)
449
+ For example if you have this in your `application.css`
495
450
 
496
- * Cache store must now be an LRU implementation.
497
- * Default digest changed to SHA1. To continue using MD5.
498
- `env.digest_class = Digest::MD5`.
451
+ ``` css
452
+ .logo {
453
+ background: url(<%= asset_url("logo.png") %>)
454
+ }
455
+ ```
499
456
 
500
- **2.10.0** (May 24, 2013)
457
+ When you modify the `logo.png` on disk, it will force `application.css` to be
458
+ recompiled so that the fingerprint will be correct in the generated asset.
501
459
 
502
- * Support for `bower.json`
460
+ You can manually make sprockets depend on any other file that is generated
461
+ by sprockets by using the `depend_on` directive. Rails implements the above
462
+ feature by auto calling `depend_on` on the original asset when the `asset_url`
463
+ is used inside of an asset.
503
464
 
504
- **2.9.3** (April 20, 2013)
465
+ ### Styling with Sass and SCSS
505
466
 
506
- * Fixed sass caching bug
467
+ [Sass](http://sass-lang.com/) is a language that compiles to CSS and
468
+ adds features like nested rules, variables, mixins and selector
469
+ inheritance.
507
470
 
508
- **2.9.2** (April 8, 2013)
471
+ If the `sass` gem is available to your application, you can use Sass
472
+ to write CSS assets in Sprockets.
509
473
 
510
- * Improve file freshness check performance
511
- * Directive processor encoding fixes
474
+ Sprockets supports both Sass syntaxes. For the original
475
+ whitespace-sensitive syntax, use the extension `.sass`. For the
476
+ new SCSS syntax, use the extension `.scss`.
512
477
 
513
- **2.9.1** (April 6, 2013)
478
+ In Rails if you have `app/application/stylesheets/foo.scss` it can
479
+ be referenced with `<%= asset_path("foo.css") %>`. When referencing
480
+ an asset in Rails, always specify the extension you want. Sprockets will
481
+ convert `foo.scss` to `foo.css`.
514
482
 
515
- * Support for Uglifier 2.x
483
+ ### Scripting with CoffeeScript
516
484
 
517
- **2.9.0** (February 25, 2013)
485
+ [CoffeeScript](http://jashkenas.github.io/coffeescript/) is a
486
+ language that compiles to the "good parts" of JavaScript, featuring a
487
+ cleaner syntax with array comprehensions, classes, and function
488
+ binding.
518
489
 
519
- * Write out gzipped variants of bundled assets.
490
+ If the `coffee-script` gem is available to your application, you can
491
+ use CoffeeScript to write JavaScript assets in Sprockets. Note that
492
+ the CoffeeScript compiler is written in JavaScript, and you will need
493
+ an [ExecJS](https://github.com/rails/execjs)-supported runtime
494
+ on your system to invoke it.
520
495
 
521
- **2.8.2** (December 10, 2012)
496
+ To write JavaScript assets with CoffeeScript, use the extension
497
+ `.coffee`.
522
498
 
523
- * Fixed top level Sass constant references
524
- * Fixed manifest logger when environment is disabled
499
+ In Rails if you have `app/application/javascripts/foo.coffee` it can
500
+ be referenced with `<%= asset_path("foo.js") %>`. When referencing
501
+ an asset in Rails, always specify the extension you want. Sprockets will
502
+ convert `foo.coffee` to `foo.js`.
525
503
 
526
- **2.8.1** (October 31, 2012)
527
504
 
528
- * Fixed Sass importer bug
505
+ ## ES6 Support
529
506
 
530
- **2.8.0** (October 16, 2012)
507
+ Sprockets 4 ships with a Babel processor. This allows you to transpile ECMAScript6 to JavaScript just like you would transpile CoffeeScript to JavaScript. To use this, modify your Gemfile:
531
508
 
532
- * Allow manifest location to be separated from output directory
533
- * Pass logical path and absolute path to each_logical_path iterator
509
+ ```ruby
510
+ gem 'babel-transpiler'
511
+ ```
534
512
 
535
- **2.7.0** (October 10, 2012)
513
+ Any asset with the extension `es6` will be treated as an ES6 file:
536
514
 
537
- * Added --css-compressor and --js-compressor command line flags
538
- * Added css/js compressor shorthand
539
- * Change default manifest.json filename to be a randomized manifest-16HEXBYTES.json
540
- * Allow nil environment to be passed to manifest
541
- * Allow manifest instance to be set on rake task
515
+ ```es6
516
+ // app/assets/javascript/application.es6
542
517
 
543
- **2.6.0** (September 19, 2012)
518
+ var square = (n) => n * n
544
519
 
545
- * Added bower component.json require support
520
+ console.log(square);
521
+ ```
546
522
 
547
- **2.5.0** (September 4, 2012)
523
+ Start a Rails server in development mode and visit `localhost:3000/assets/application.js`, and this asset will be transpiled to JavaScript:
548
524
 
549
- * Fixed Ruby 2.0 RegExp warning
550
- * Provide stubbed implementation of context *_path helpers
551
- * Add SassCompressor
525
+ ```js
526
+ var square = function square(n) {
527
+ return n * n;
528
+ };
552
529
 
553
- **2.4.5** (July 10, 2012)
530
+ console.log(square);
531
+ ```
554
532
 
555
- * Tweaked some logger levels
556
533
 
557
- **2.4.4** (July 2, 2012)
534
+ ### JavaScript Templating with EJS and Eco
558
535
 
559
- * Canonicalize logical path extensions
560
- * Check absolute paths passed to depend_on
536
+ Sprockets supports *JavaScript templates* for client-side rendering of
537
+ strings or markup. JavaScript templates have the special format
538
+ extension `.jst` and are compiled to JavaScript functions.
561
539
 
562
- **2.4.3** (May 16, 2012)
540
+ When loaded, a JavaScript template function can be accessed by its
541
+ logical path as a property on the global `JST` object. Invoke a
542
+ template function to render the template as a string. The resulting
543
+ string can then be inserted into the DOM.
563
544
 
564
- * Exposed :sprockets in sass options
565
- * Include dependency paths in asset mtime
545
+ ```
546
+ <!-- templates/hello.jst.ejs -->
547
+ <div>Hello, <span><%= name %></span>!</div>
566
548
 
567
- **2.4.2** (May 7, 2012)
549
+ // application.js
550
+ //= require templates/hello
551
+ $("#hello").html(JST["templates/hello"]({ name: "Sam" }));
552
+ ```
568
553
 
569
- * Fixed MultiJson feature detect
554
+ Sprockets supports two JavaScript template languages:
555
+ [EJS](https://github.com/sstephenson/ruby-ejs), for embedded
556
+ JavaScript, and [Eco](https://github.com/sstephenson/ruby-eco), for
557
+ embedded CoffeeScript. Both languages use the familiar `<% … %>`
558
+ syntax for embedding logic in templates.
570
559
 
571
- **2.4.1** (April 26, 2012)
560
+ If the `ejs` gem is available to your application, you can use EJS
561
+ templates in Sprockets. EJS templates have the extension `.jst.ejs`.
572
562
 
573
- * Fixed MultiJson API change
574
- * Fixed gzip mtime
563
+ If the `eco` gem is available to your application, you can use [Eco
564
+ templates](https://github.com/sstephenson/eco) in Sprockets. Eco
565
+ templates have the extension `.jst.eco`. Note that the `eco` gem
566
+ depends on the CoffeeScript compiler, so the same caveats apply as
567
+ outlined above for the CoffeeScript engine.
575
568
 
576
- **2.4.0** (March 27, 2012)
569
+ ### Minifying Assets
577
570
 
578
- * Added global path registry
579
- * Added global processor registry
571
+ Several JavaScript and CSS minifiers are available through shorthand.
580
572
 
581
- **2.3.2** (March 26, 2012)
573
+ In Rails you will specify them with:
582
574
 
583
- * Fix Context#logical_path with dots
575
+ ```ruby
576
+ config.assets.js_compressor = :uglify
577
+ config.assets.css_compressor = :scss
578
+ ```
584
579
 
585
- **2.3.1** (February 11, 2012)
580
+ If you're not using Rails, configure this directly on the "environment".
586
581
 
587
- * Added bytesize to manifest
588
- * Added Asset#bytesize alias
589
- * Security: Check path for forbidden access after unescaping
582
+ ``` ruby
583
+ environment.js_compressor = :uglify
584
+ environment.css_compressor = :scss
585
+ ```
590
586
 
591
- **2.3.0** (January 16, 2012)
587
+ If you are using Sprockets directly with a Rack app, don't forget to add
588
+ the `uglifier` and `sass` gems to your Gemfile when using above options.
592
589
 
593
- * Added special Sass importer that automatically tracks any `@import`ed files.
590
+ ### Gzip
594
591
 
595
- **2.2.0** (January 10, 2012)
592
+ By default when Sprockets generates a compiled asset file it will also produce a gzipped copy of that file. Sprockets only gzips non-binary files such as CSS, javascript, and SVG files.
596
593
 
597
- * Added `sprockets` command line utility.
598
- * Added rake/sprocketstask.
599
- * Added json manifest log of compiled assets.
600
- * Added `stub` directive that allows you to exclude files from the bundle.
601
- * Added per environment external encoding (Environment#default_external_encoding). Defaults to UTF-8. Fixes issues where LANG is not set correctly and Rubys default external is set to ASCII.
594
+ For example if Sprockets is generating
602
595
 
603
- **2.1.2** (November 20, 2011)
596
+ ```
597
+ application-12345.css
598
+ ```
604
599
 
605
- * Disabled If-Modified-Since server checks. Fixes some browser caching issues when serving the asset body only. If-None-Match caching is sufficient.
600
+ Then it will also generate a compressed copy in
606
601
 
607
- **2.1.1** (November 18, 2011)
602
+ ```
603
+ application-12345.css.gz
604
+ ```
608
605
 
609
- * Fix windows absolute path check bug.
606
+ This behavior can be disabled, refer to your framework specific documentation.
610
607
 
611
- **2.1.0** (November 11, 2011)
608
+ ### Serving Assets
612
609
 
613
- * Directive comment lines are now turned into empty lines instead of removed. This way line numbers in
614
- CoffeeScript syntax errors are correct.
615
- * Performance and caching bug fixes.
610
+ In production you should generate your assets to a directory on disk and serve them either via Nginx or a feature like Rail's `config.public_file_server.enabled = true`.
616
611
 
617
- **2.0.3** (October 17, 2011)
612
+ On Rails you can generate assets by running:
618
613
 
619
- * Detect format extensions from right to left.
620
- * Make JST namespace configurable.
614
+ ```term
615
+ $ RAILS_ENV=production rake assets:precompile
616
+ ```
621
617
 
622
- **2.0.2** (October 4, 2011)
618
+ In development Rails will serve assets from `Sprockets::Server`.
623
619
 
624
- * Fixed loading stale cache from bundler gems.
620
+ ## Contributing to Sprockets
625
621
 
626
- **2.0.1** (September 30, 2011)
622
+ Sprockets is the work of hundreds of contributors. You're encouraged to submit pull requests, propose
623
+ features and discuss issues.
627
624
 
628
- * Fixed bug with fingerprinting file names with multiple dots.
629
- * Decode URIs as default internal.
630
- * Fix symlinked asset directories.
625
+ See [CONTRIBUTING](CONTRIBUTING.md).
631
626
 
632
- **2.0.0** (August 29, 2011)
627
+ ### Version History
633
628
 
634
- * Initial public release.
629
+ Please see the [CHANGELOG](https://github.com/rails/sprockets/tree/master/CHANGELOG.md)
635
630
 
636
631
  ## License
637
-
638
- Copyright &copy; 2014 Sam Stephenson <<sstephenson@gmail.com>>
639
-
640
- Copyright &copy; 2014 Joshua Peek <<josh@joshpeek.com>>
641
-
642
- Sprockets is distributed under an MIT-style license. See LICENSE for
643
- details.
632
+ Sprockets is released under the [MIT License](MIT-LICENSE).