ember-cli-rails-assets 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +31 -6
- data/app/helpers/ember_cli_rails_assets_helper.rb +53 -10
- data/lib/ember_cli/assets/errors.rb +1 -0
- data/lib/ember_cli/assets/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a14199abf9cfa5f0faf079ea10fbc134cf701d48d016da69f7d43ed64256fbdf
|
|
4
|
+
data.tar.gz: b5d351892f33578fcae89ccdb77966393b2682f634dfe5f3d0ee384e42e095b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 52c74aa8f6993613dd16c7e762260ce2818654d043ac80b1627392ac2fbd3cdcbcc3231a9b67125f107b1de4b0aab97f52aaa7f6f9f9fa34025a7fb92a160244
|
|
7
|
+
data.tar.gz: 4c639e39672b4cbc07281153c20e3a27d68f233e20a0abd3ab2b03ae130c71c807db7a91acbbcb05121d130fb8f4484e9baedfa1d386da0cf5eca171013c70d7
|
data/README.md
CHANGED
|
@@ -33,8 +33,9 @@ $ bundle install
|
|
|
33
33
|
To configure your project to use `ember-cli-rails`, follow the instructions
|
|
34
34
|
listed in the [`ember-cli-rails` README][README].
|
|
35
35
|
|
|
36
|
-
To configure
|
|
37
|
-
|
|
36
|
+
To configure a classic (Broccoli-based) Ember application to use
|
|
37
|
+
`ember-cli-rails-assets`, ensure its `ember-cli-build.js` includes the
|
|
38
|
+
following values:
|
|
38
39
|
|
|
39
40
|
```js
|
|
40
41
|
// frontend/ember-cli-build.js
|
|
@@ -54,6 +55,27 @@ module.exports = function(defaults) {
|
|
|
54
55
|
|
|
55
56
|
[README]: https://github.com/tricknotes/ember-cli-rails#readme
|
|
56
57
|
|
|
58
|
+
### Vite-based applications
|
|
59
|
+
|
|
60
|
+
Vite-based applications (generated with `ember-cli >= 6.8`) require no build
|
|
61
|
+
configuration. For them, use `include_ember_script_tags` on its own: it emits
|
|
62
|
+
everything the application needs to boot — the configuration `<meta>` tag, the
|
|
63
|
+
stylesheet and `modulepreload` links, and the ES module script tags —
|
|
64
|
+
extracted from the generated `index.html`:
|
|
65
|
+
|
|
66
|
+
```erb
|
|
67
|
+
<%= include_ember_script_tags :frontend %>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
When ember-cli-rails serves the application from Vite's development server in
|
|
71
|
+
`development`, `include_ember_script_tags` reads `index.html` from the server
|
|
72
|
+
instead of a build directory, and emits the startup tags with absolute URLs
|
|
73
|
+
pointing at the server. Nothing is built, so changes to the application are
|
|
74
|
+
picked up by reloading the page.
|
|
75
|
+
|
|
76
|
+
`include_ember_stylesheet_tags` only supports classic applications, and raises
|
|
77
|
+
an error when called for a Vite-based application.
|
|
78
|
+
|
|
57
79
|
## Mount
|
|
58
80
|
|
|
59
81
|
Mount the Ember application (in this example, the `frontend` application) to the
|
|
@@ -114,19 +136,22 @@ To render the asset elements without using a `<base>` element, pass the URL or
|
|
|
114
136
|
path to prepend:
|
|
115
137
|
|
|
116
138
|
```erb
|
|
117
|
-
|
|
139
|
+
<!-- assuming Ember's assets are mounted to `"/"` -->
|
|
118
140
|
<%= include_ember_script_tags :frontend, prepend: "/" %>
|
|
119
141
|
<%= include_ember_stylesheet_tags :frontend, prepend: "/" %>
|
|
120
142
|
|
|
121
|
-
|
|
122
|
-
<%=
|
|
143
|
+
<!-- assuming Ember's assets are mounted to `"/admin_panel/"` -->
|
|
144
|
+
<%= include_ember_script_tags :admin_panel, prepend: "/admin_panel/" %>
|
|
145
|
+
<%= include_ember_stylesheet_tags :admin_panel, prepend: "/admin_panel/" %>
|
|
123
146
|
```
|
|
124
147
|
|
|
125
148
|
## EmberCLI support
|
|
126
149
|
|
|
127
150
|
This project supports:
|
|
128
151
|
|
|
129
|
-
* EmberCLI versions `>= 1.13.13`
|
|
152
|
+
* EmberCLI versions `>= 1.13.13` using the classic (Broccoli-based) build
|
|
153
|
+
* EmberCLI versions `>= 6.8` using the Vite-based build, with
|
|
154
|
+
`include_ember_script_tags` only
|
|
130
155
|
|
|
131
156
|
## Ruby and Rails support
|
|
132
157
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require "ember_cli/assets/errors"
|
|
1
2
|
require "ember_cli/assets/lookup"
|
|
2
3
|
require "ember_cli/assets/paths"
|
|
3
4
|
|
|
@@ -6,19 +7,36 @@ module EmberCliRailsAssetsHelper
|
|
|
6
7
|
app = EmberCli[name]
|
|
7
8
|
app.build
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if paths.vite?
|
|
12
|
-
vite_ember_script_tags(paths, prepend)
|
|
10
|
+
if dev_server?(app)
|
|
11
|
+
dev_server_ember_script_tags(app)
|
|
13
12
|
else
|
|
14
|
-
|
|
13
|
+
paths = EmberCli::Assets::Paths.new(app)
|
|
14
|
+
|
|
15
|
+
if paths.vite?
|
|
16
|
+
vite_ember_script_tags(paths, prepend)
|
|
17
|
+
else
|
|
18
|
+
classic_ember_script_tags(app, prepend)
|
|
19
|
+
end
|
|
15
20
|
end
|
|
16
21
|
end
|
|
17
22
|
|
|
18
23
|
def include_ember_stylesheet_tags(name, prepend: "")
|
|
19
|
-
EmberCli[name]
|
|
24
|
+
app = EmberCli[name]
|
|
25
|
+
app.build
|
|
26
|
+
|
|
27
|
+
paths = EmberCli::Assets::Paths.new(app)
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
if dev_server?(app) || paths.vite?
|
|
30
|
+
raise EmberCli::Assets::NotSupportedError, <<~MSG
|
|
31
|
+
`include_ember_stylesheet_tags` does not support Vite-based
|
|
32
|
+
applications (`ember-cli >= 6.8`).
|
|
33
|
+
|
|
34
|
+
`include_ember_script_tags` already emits their stylesheet tags,
|
|
35
|
+
so remove this call.
|
|
36
|
+
MSG
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
assets = EmberCli::Assets::Lookup.new(app)
|
|
22
40
|
|
|
23
41
|
assets.stylesheet_assets.
|
|
24
42
|
map { |src| [prepend, src].join }.
|
|
@@ -28,6 +46,22 @@ module EmberCliRailsAssetsHelper
|
|
|
28
46
|
|
|
29
47
|
private
|
|
30
48
|
|
|
49
|
+
# Whether ember-cli-rails serves the application from Vite's development
|
|
50
|
+
# server. Older ember-cli-rails releases have no development server, so
|
|
51
|
+
# feature-detect the reader.
|
|
52
|
+
def dev_server?(app)
|
|
53
|
+
app.respond_to?(:dev_server?) && app.dev_server?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# The application is served by Vite's development server, so read
|
|
57
|
+
# `index.html` from the server instead of a build directory, and rewrite
|
|
58
|
+
# its root-relative URLs to absolute URLs on the server — the same way
|
|
59
|
+
# ember-cli-rails serves the document itself. `app.build` has already
|
|
60
|
+
# booted the server.
|
|
61
|
+
def dev_server_ember_script_tags(app)
|
|
62
|
+
vite_startup_tags(app.dev_server.index_html, prefix: app.dev_server.origin)
|
|
63
|
+
end
|
|
64
|
+
|
|
31
65
|
# Classic builds ship a fixed set of scripts (vendor and app) resolved
|
|
32
66
|
# through the asset map, so emit a plain script tag per JavaScript asset
|
|
33
67
|
# with `prepend` joined onto each path.
|
|
@@ -44,15 +78,24 @@ module EmberCliRailsAssetsHelper
|
|
|
44
78
|
# the tags required for startup (including the config meta tag and
|
|
45
79
|
# stylesheets) and remap root-absolute paths onto the mount point.
|
|
46
80
|
def vite_ember_script_tags(paths, prepend)
|
|
47
|
-
|
|
48
|
-
|
|
81
|
+
vite_startup_tags(paths.index_html.read, prefix: prepend.to_s.chomp("/"))
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Extracts the tags a Vite-based application needs to boot from an
|
|
85
|
+
# `index.html` document, with `prefix` joined onto every root-relative
|
|
86
|
+
# URL. Protocol-relative URLs (`//`) are left alone.
|
|
87
|
+
def vite_startup_tags(html, prefix:)
|
|
88
|
+
document = Nokogiri::HTML5(html)
|
|
49
89
|
|
|
50
90
|
tags = document.css(
|
|
51
91
|
'meta[name$="/config/environment"], link[rel="stylesheet"], link[rel="modulepreload"], script'
|
|
52
92
|
).map do |tag|
|
|
53
93
|
%w(href src).each do |attribute|
|
|
54
94
|
value = tag[attribute]
|
|
55
|
-
|
|
95
|
+
|
|
96
|
+
if value&.start_with?("/") && !value.start_with?("//")
|
|
97
|
+
tag[attribute] = "#{prefix}#{value}"
|
|
98
|
+
end
|
|
56
99
|
end
|
|
57
100
|
tag.to_html.html_safe
|
|
58
101
|
end
|