-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Adding AssetPipeline & ImportMaps #1358
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "asset_pipeline" | ||
|
||
FRONT_LOADER = AssetPipeline::FrontLoader.new(js_source_path: Path["src/javascript"], js_output_path: Path["public"]) do |import_maps| | ||
import_map = AssetPipeline::ImportMap.new | ||
|
||
if Amber.settings.auto_reload | ||
import_map.add_import("client_reload", "/client_reload.js") | ||
end | ||
|
||
import_map.add_import("@popperjs/core", "https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js") | ||
import_map.add_import("bootstrap", "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.esm.min.js") | ||
import_map.add_import("amber", "/amber.js") | ||
|
||
import_maps << import_map | ||
drujensen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
drujensen marked this conversation as resolved.
Show resolved
Hide resolved
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
let tryReload | ||
|
||
export function initializeWebSockets() { | ||
console.log("initializeWebSockets has run...") | ||
|
||
tryReload = async function () { | ||
try { | ||
const response = await fetch(window.location.href); | ||
if (!response.ok) { | ||
setTimeout(tryReload, 1000); | ||
} else { | ||
window.location.reload(); | ||
} | ||
} catch (error) { | ||
setTimeout(tryReload, 1000); | ||
} | ||
} | ||
|
||
if ('WebSocket' in window) { | ||
const protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://' | ||
const address = protocol + window.location.host + '/client-reload' | ||
const socket = new WebSocket(address) | ||
|
||
socket.onmessage = function (msg) { | ||
console.log(msg) | ||
if (msg.data == 'reload') { | ||
tryReload() | ||
} | ||
} | ||
|
||
socket.onclose = function () { | ||
setTimeout(tryReload, 1000) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,9 +38,15 @@ | |
</div> | ||
</div> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> | ||
|
||
<script type="module" src="/js/amber.js"></script> | ||
<%="<"%>%- if Amber.settings.auto_reload? -%><script src="/js/client_reload.js"></script><%="<"%>%- end -%> | ||
<%= "<"%>%= FRONT_LOADER.render_import_map_tag %> | ||
<script type="module"> | ||
import { initialize } from 'amber' | ||
initialize() | ||
|
||
<%= "<"%>%- if Amber.settings.auto_reload? %> | ||
import { initializeWebSockets } from 'client_reload' | ||
initializeWebSockets() | ||
<%= "<"%>% end %> | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,9 @@ html | |
|
||
.main== content | ||
|
||
script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" | ||
== FRONT_LOADER.render_import_map_tag | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit cosmetic, but maybe a helper function like If the plan is to have import maps as a built in feature, maybe would be worth to deal with it like Amber does with routes and settings, a file Amber::Server.import_maps(source_dir: "src/javascript", output_dir: "public") do |import_maps|
...
end OR, to not fill Amber::Server with frontend stuff: Amber::ImportMaps.configure(source_dir: "src/javascript", output_dir: "public") do
... |
||
|
||
script type="module" src="/js/amber.js" | ||
- if Amber.settings.auto_reload? | ||
script src="/js/client_reload.js" | ||
script type="module" | ||
= "import { initialize } from 'amber'"; | ||
- if Amber.settings.auto_reload? | ||
= "import { initializeWebSockets } from 'client_reload'"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wdyt of
assets/javascript
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kicked that around. If the deployment doesn't require the entire code base be cloned, then it makes total sense.
But, wouldn't most dockerized/containerized deploys mean the entire code base was cloned into the image and then deployed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just copy the
assets
directory to the docker image instead ofsrc/javascript
. I think it will actually make creating the image easier.