propshaft 0.1.3 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -5
- data/lib/propshaft/assembly.rb +1 -1
- data/lib/propshaft/asset.rb +10 -1
- data/lib/propshaft/load_path.rb +20 -3
- data/lib/propshaft/railtie.rb +11 -4
- data/lib/propshaft/version.rb +1 -1
- data/lib/propshaft.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f01db7988c70a623917c5239f4b76cef03e3364b86f3bb1b9850691d1045d3e1
|
4
|
+
data.tar.gz: 066dab4410e31551036e8f539cb351b8c4a6d7c53ae9bd02343b228be16fc85f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b09d882ebf32f6afda261a3dbf32ab322e25b1756b802b70e4b6b16f73f3d91404e8b51be6e5c54a1335332744305d3d149712136cbbdabc67b258229178b9f
|
7
|
+
data.tar.gz: 65a13d00417ff13f2678660038ebb7f33074e56b0277b7c51e9df170f9e393ec17cd5ff5ddc888b4e24c469df33ba4f5d8acb19ecf5a2b7626d41c22dac0d781
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Propshaft
|
2
2
|
|
3
|
-
Propshaft is an asset pipeline library for Rails. It's built for era where bundling assets to save on HTTP connections is no longer urgent, where JavaScript and CSS
|
3
|
+
Propshaft is an asset pipeline library for Rails. It's built for an era where bundling assets to save on HTTP connections is no longer urgent, where JavaScript and CSS are either compiled by dedicated Node.js bundlers or served directly to the browsers, and where increases in bandwidth have made the need for minification less pressing. These factors allow for a dramatically simpler and faster asset pipeline compared to previous options, like Sprockets.
|
4
4
|
|
5
|
-
So that's what Propshaft doesn't do. Here's what it
|
5
|
+
So that's what Propshaft doesn't do. Here's what it does provide:
|
6
6
|
|
7
7
|
1. **Configurable load path**: You can register directories from multiple places in your app and gems, and reference assets from all of these paths as though they were one.
|
8
8
|
1. **Digest stamping**: All assets in the load path will be copied (or compiled) in a precompilation step for production that also stamps all of them with a digest hash, so you can use long-expiry cache headers for better performance. The digested assets can be referred to through their logical path because the processing leaves a manifest file that provides a way to translate.
|
@@ -17,16 +17,21 @@ With Rails 7+, you can start a new application with propshaft using `rails new m
|
|
17
17
|
|
18
18
|
## Usage
|
19
19
|
|
20
|
-
Propshaft makes all the assets from all the paths
|
20
|
+
Propshaft makes all the assets from all the paths it's been configured with through `config.assets.paths` available for serving and will copy all of them into `public/assets` when precompiling. This is unlike Sprockets, which did not copy over assets that hadn't been explicitly included in one of the bundled assets.
|
21
21
|
|
22
|
-
These assets can be referenced through their logical path using the normal helpers like `asset_path`, `image_tag`, `javascript_include_tag`, and all the other asset helper tags. These logical references are automatically converted into digest-aware paths in production when `assets:precompile` has been run (through a
|
22
|
+
These assets can be referenced through their logical path using the normal helpers like `asset_path`, `image_tag`, `javascript_include_tag`, and all the other asset helper tags. These logical references are automatically converted into digest-aware paths in production when `assets:precompile` has been run (through a JSON mapping file found in `public/assets/.manifest.json`).
|
23
23
|
|
24
24
|
Additionally, Propshaft ships with a CSS function called `asset-path("image.svg")` that'll be compiled into `url("/assets/image-f2e1ec14d6856e1958083094170ca6119c529a73.svg")` when doing `assets:precompile`. This function is applied to all `.css` files.
|
25
25
|
|
26
26
|
|
27
|
+
## Bypassing the digest step
|
28
|
+
|
29
|
+
If you need to put multiple files that refer to each other through Propshaft, like a JavaScript file and its source map, you have to digest these files in advance to retain stable file names. Propshaft looks for the specific pattern of `-[digest].digested.js` as the postfix to any asset file as an indication that the file has already been digested.
|
30
|
+
|
31
|
+
|
27
32
|
## Migrating from Sprockets
|
28
33
|
|
29
|
-
Propshaft does a lot less than Sprockets, by design, so it might well be a fair bit of work to migrate
|
34
|
+
Propshaft does a lot less than Sprockets, by design, so it might well be a fair bit of work to migrate if it's even desirable. This is particularly true if you rely on Sprockets to provide any form of transpiling, like CoffeeScript or Sass, or if you rely on any gems that do. You'll need to either stop transpiling or use a Node-based transpiler, like those in `jsbundling-rails` and `cssbundling-rails`.
|
30
35
|
|
31
36
|
On the other hand, if you're already bundling JavaScript and CSS through a Node-based setup, then Propshaft is going to slot in easily. Since you don't need another tool to bundle or transpile. Just to digest and serve.
|
32
37
|
|
data/lib/propshaft/assembly.rb
CHANGED
data/lib/propshaft/asset.rb
CHANGED
@@ -25,10 +25,19 @@ class Propshaft::Asset
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def digested_path
|
28
|
-
|
28
|
+
if already_digested?
|
29
|
+
logical_path
|
30
|
+
else
|
31
|
+
logical_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def ==(other_asset)
|
32
36
|
logical_path.hash == other_asset.logical_path.hash
|
33
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def already_digested?
|
41
|
+
logical_path.to_s =~ /-([0-9a-f]{7,128})\.digested\.[^.]+\z/
|
42
|
+
end
|
34
43
|
end
|
data/lib/propshaft/load_path.rb
CHANGED
@@ -27,15 +27,28 @@ class Propshaft::LoadPath
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
# Returns a ActiveSupport::FileUpdateChecker object configured to clear the cache of the load_path
|
31
|
+
# when the directories passed during its initialization have changes. This is used in development
|
32
|
+
# and test to ensure the map caches are reset when javascript files are changed.
|
33
|
+
def cache_sweeper
|
34
|
+
@cache_sweeper ||= begin
|
35
|
+
exts_to_watch = Mime::EXTENSION_LOOKUP.map(&:first)
|
36
|
+
files_to_watch = Array(paths).collect { |dir| [ dir.to_s, exts_to_watch ] }.to_h
|
37
|
+
|
38
|
+
Rails.application.config.file_watcher.new([], files_to_watch) do
|
39
|
+
clear_cache
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
30
44
|
private
|
31
45
|
def assets_by_path
|
32
|
-
Hash.new.tap do |mapped|
|
46
|
+
@cached_assets_by_path ||= Hash.new.tap do |mapped|
|
33
47
|
paths.each do |path|
|
34
48
|
all_files_from_tree(path).each do |file|
|
35
49
|
logical_path = file.relative_path_from(path)
|
36
|
-
|
37
50
|
mapped[logical_path.to_s] ||= Propshaft::Asset.new(file, logical_path: logical_path)
|
38
|
-
end
|
51
|
+
end if path.exist?
|
39
52
|
end
|
40
53
|
end
|
41
54
|
end
|
@@ -43,4 +56,8 @@ class Propshaft::LoadPath
|
|
43
56
|
def all_files_from_tree(path)
|
44
57
|
path.children.flat_map { |child| child.directory? ? all_files_from_tree(child) : child }
|
45
58
|
end
|
59
|
+
|
60
|
+
def clear_cache
|
61
|
+
@cached_assets_by_path = nil
|
62
|
+
end
|
46
63
|
end
|
data/lib/propshaft/railtie.rb
CHANGED
@@ -4,7 +4,7 @@ require "active_support/ordered_options"
|
|
4
4
|
|
5
5
|
# FIXME: There's gotta be a better way than this hack?
|
6
6
|
class Rails::Engine < Rails::Railtie
|
7
|
-
initializer
|
7
|
+
initializer "propshaft.append_assets_path", group: :all do |app|
|
8
8
|
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
|
9
9
|
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
|
10
10
|
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
|
@@ -14,9 +14,10 @@ end
|
|
14
14
|
module Propshaft
|
15
15
|
class Railtie < ::Rails::Railtie
|
16
16
|
config.assets = ActiveSupport::OrderedOptions.new
|
17
|
-
config.assets.paths
|
18
|
-
config.assets.prefix
|
19
|
-
config.assets.compilers
|
17
|
+
config.assets.paths = []
|
18
|
+
config.assets.prefix = "/assets"
|
19
|
+
config.assets.compilers = [ [ "text/css", Propshaft::Compilers::CssAssetUrls ] ]
|
20
|
+
config.assets.sweep_cache = Rails.env.development? || Rails.env.test?
|
20
21
|
|
21
22
|
config.after_initialize do |app|
|
22
23
|
config.assets.output_path ||=
|
@@ -31,6 +32,12 @@ module Propshaft
|
|
31
32
|
ActiveSupport.on_load(:action_view) do
|
32
33
|
include Propshaft::Helper
|
33
34
|
end
|
35
|
+
|
36
|
+
if config.assets.sweep_cache
|
37
|
+
ActiveSupport.on_load(:action_controller_base) do
|
38
|
+
before_action { Rails.application.assets.load_path.cache_sweeper.execute_if_updated }
|
39
|
+
end
|
40
|
+
end
|
34
41
|
end
|
35
42
|
|
36
43
|
rake_tasks do |app|
|
data/lib/propshaft/version.rb
CHANGED
data/lib/propshaft.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: propshaft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09
|
11
|
+
date: 2021-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|