1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Update Asset Pipeline Guide to describe how Sprockets 4 works

Fixes https://github.com/rails/rails/issues/43203

To test this, I
- Uninstalled all Rails gems
- `gem install rails --pre`
- `rails new asset_test`
- Made these changes, to use Sprockets for JS instead of importmaps: 7d961765c0
- Confirmed that no source map is rendered by default
- Set `config.assets.debug = true`, and confirmed that a source map is now rendered
This commit is contained in:
Alex Ghiculescu 2021-12-09 17:42:02 -06:00 committed by GitHub
parent bcc1c0e4af
commit 8d3edd593b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -508,8 +508,7 @@ wouldn't understand ERB and therefore you would run into problems.
In Development
--------------
In development mode, assets are served as separate files in the order they are
specified in the manifest file.
In development mode, assets are served as a concatenated file.
This manifest `app/assets/javascripts/application.js`:
@ -522,13 +521,9 @@ This manifest `app/assets/javascripts/application.js`:
would generate this HTML:
```html
<script src="/assets/core.js?body=1"></script>
<script src="/assets/projects.js?body=1"></script>
<script src="/assets/tickets.js?body=1"></script>
<script src="/assets/application-728742f3b9daa182fe7c831f6a3b8fa87609b4007fdc2f87c134a07b19ad93fb.js"></script>
```
The `body` param is required by Sprockets.
### Raise an Error When an Asset is Not Found
If you are using sprockets-rails >= 3.2.0 you can configure what happens
@ -553,43 +548,26 @@ config.assets.digest = false
When this option is true, digests will be generated for asset URLs.
### Turning Debugging Off
### Turning Source Maps On
You can turn off debug mode by updating `config/environments/development.rb` to
You can turn on source maps by updating `config/environments/development.rb` to
include:
```ruby
config.assets.debug = false
config.assets.debug = true
```
When debug mode is off, Sprockets concatenates and runs the necessary
preprocessors on all files. With debug mode turned off the manifest above would
generate instead:
```html
<script src="/assets/application.js"></script>
```
When debug mode is on, Sprockets will generate a Source Map for each asset. This
allows you to debug each file individually in your browser's developer tools.
Assets are compiled and cached on the first request after the server is started.
Sprockets sets a `must-revalidate` Cache-Control HTTP header to reduce request
overhead on subsequent requests - on these the browser gets a 304 (Not Modified)
response.
If any of the files in the manifest have changed between requests, the server
If any of the files in the manifest change between requests, the server
responds with a new compiled file.
Debug mode can also be enabled in Rails helper methods:
```erb
<%= stylesheet_link_tag "application", debug: true %>
<%= javascript_include_tag "application", debug: true %>
```
The `:debug` option is redundant if debug mode is already on.
You can also enable compression in development mode, and
disable it on-demand as required for debugging.
In Production
-------------