mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 05:37:59 +01:00
Vite HMR for JS/TS (and jankily for CSS) (#242)
* prelim work on vite reload * the best solution to a problem is usually the easiest one
This commit is contained in:
parent
ac908d2efd
commit
dd8c2c81d9
8 changed files with 51 additions and 5 deletions
|
@ -8,3 +8,12 @@
|
||||||
// Our code
|
// Our code
|
||||||
import './ujs';
|
import './ujs';
|
||||||
import './when-ready';
|
import './when-ready';
|
||||||
|
|
||||||
|
// When developing CSS, include the relevant CSS you're working on here
|
||||||
|
// in order to enable HMR (live reload) on it.
|
||||||
|
// Would typically be either the theme file, or any additional file
|
||||||
|
// you later intend to put in the <link> tag.
|
||||||
|
|
||||||
|
// import '../css/themes/default.scss';
|
||||||
|
// import '../css/themes/dark.scss';
|
||||||
|
// import '../css/themes/red.scss';
|
||||||
|
|
|
@ -15,6 +15,16 @@ config :philomena, PhilomenaWeb.Endpoint,
|
||||||
code_reloader: true,
|
code_reloader: true,
|
||||||
check_origin: false,
|
check_origin: false,
|
||||||
watchers: [
|
watchers: [
|
||||||
|
node: [
|
||||||
|
"node_modules/vite/bin/vite.js",
|
||||||
|
"--mode",
|
||||||
|
"development",
|
||||||
|
"--host",
|
||||||
|
"0.0.0.0",
|
||||||
|
"--config",
|
||||||
|
"vite.config.ts",
|
||||||
|
cd: Path.expand("../assets", __DIR__)
|
||||||
|
],
|
||||||
node: [
|
node: [
|
||||||
"node_modules/vite/bin/vite.js",
|
"node_modules/vite/bin/vite.js",
|
||||||
"build",
|
"build",
|
||||||
|
|
|
@ -137,6 +137,9 @@ if config_env() == :prod do
|
||||||
|
|
||||||
# Do not relax CSP in production
|
# Do not relax CSP in production
|
||||||
config :philomena, csp_relaxed: false
|
config :philomena, csp_relaxed: false
|
||||||
|
|
||||||
|
# Disable Vite HMR in prod
|
||||||
|
config :philomena, vite_reload: false
|
||||||
else
|
else
|
||||||
# Don't send email in development
|
# Don't send email in development
|
||||||
config :philomena, Philomena.Mailer, adapter: Bamboo.LocalAdapter
|
config :philomena, Philomena.Mailer, adapter: Bamboo.LocalAdapter
|
||||||
|
@ -146,4 +149,7 @@ else
|
||||||
|
|
||||||
# Relax CSP rules in development and test servers
|
# Relax CSP rules in development and test servers
|
||||||
config :philomena, csp_relaxed: true
|
config :philomena, csp_relaxed: true
|
||||||
|
|
||||||
|
# Enable Vite HMR
|
||||||
|
config :philomena, vite_reload: true
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,6 +48,8 @@ services:
|
||||||
- postgres
|
- postgres
|
||||||
- elasticsearch
|
- elasticsearch
|
||||||
- redis
|
- redis
|
||||||
|
ports:
|
||||||
|
- '5173:5173'
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:16.2-alpine
|
image: postgres:16.2-alpine
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM elixir:1.16.1-alpine
|
FROM elixir:1.16.2-alpine
|
||||||
|
|
||||||
ADD https://api.github.com/repos/philomena-dev/FFmpeg/git/refs/heads/release/6.1 /tmp/ffmpeg_version.json
|
ADD https://api.github.com/repos/philomena-dev/FFmpeg/git/refs/heads/release/6.1 /tmp/ffmpeg_version.json
|
||||||
RUN (echo "https://github.com/philomena-dev/prebuilt-ffmpeg/raw/master"; cat /etc/apk/repositories) > /tmp/repositories \
|
RUN (echo "https://github.com/philomena-dev/prebuilt-ffmpeg/raw/master"; cat /etc/apk/repositories) > /tmp/repositories \
|
||||||
|
@ -24,4 +24,5 @@ COPY docker/app/run-test /usr/local/bin/run-test
|
||||||
COPY docker/app/safe-rsvg-convert /usr/local/bin/safe-rsvg-convert
|
COPY docker/app/safe-rsvg-convert /usr/local/bin/safe-rsvg-convert
|
||||||
COPY docker/app/purge-cache /usr/local/bin/purge-cache
|
COPY docker/app/purge-cache /usr/local/bin/purge-cache
|
||||||
ENV PATH=$PATH:/root/.cargo/bin
|
ENV PATH=$PATH:/root/.cargo/bin
|
||||||
|
EXPOSE 5173
|
||||||
CMD run-development
|
CMD run-development
|
||||||
|
|
|
@ -24,8 +24,9 @@ defmodule PhilomenaWeb.ContentSecurityPolicyPlug do
|
||||||
|
|
||||||
csp_config = [
|
csp_config = [
|
||||||
{:default_src, ["'self'"]},
|
{:default_src, ["'self'"]},
|
||||||
{:script_src, ["'self'" | script_src]},
|
{:script_src, [default_script_src() | script_src]},
|
||||||
{:style_src, ["'self'" | style_src]},
|
{:connect_src, [default_connect_src()]},
|
||||||
|
{:style_src, [default_style_src() | style_src]},
|
||||||
{:object_src, ["'none'"]},
|
{:object_src, ["'none'"]},
|
||||||
{:frame_ancestors, ["'none'"]},
|
{:frame_ancestors, ["'none'"]},
|
||||||
{:frame_src, frame_src || ["'none'"]},
|
{:frame_src, frame_src || ["'none'"]},
|
||||||
|
@ -63,6 +64,14 @@ defmodule PhilomenaWeb.ContentSecurityPolicyPlug do
|
||||||
|
|
||||||
defp cdn_uri, do: Application.get_env(:philomena, :cdn_host) |> to_uri()
|
defp cdn_uri, do: Application.get_env(:philomena, :cdn_host) |> to_uri()
|
||||||
defp camo_uri, do: Application.get_env(:philomena, :camo_host) |> to_uri()
|
defp camo_uri, do: Application.get_env(:philomena, :camo_host) |> to_uri()
|
||||||
|
defp vite_reload?, do: Application.get_env(:philomena, :vite_reload)
|
||||||
|
|
||||||
|
defp default_script_src, do: if(vite_reload?(), do: "'self' localhost:5173", else: "'self'")
|
||||||
|
|
||||||
|
defp default_connect_src,
|
||||||
|
do: if(vite_reload?(), do: "'self' localhost:5173 ws://localhost:5173", else: "'self'")
|
||||||
|
|
||||||
|
defp default_style_src, do: if(vite_reload?(), do: "'self' 'unsafe-inline'", else: "'self'")
|
||||||
|
|
||||||
defp to_uri(host) when host in [nil, ""], do: ""
|
defp to_uri(host) when host in [nil, ""], do: ""
|
||||||
defp to_uri(host), do: URI.to_string(%URI{scheme: "https", host: host})
|
defp to_uri(host), do: URI.to_string(%URI{scheme: "https", host: host})
|
||||||
|
|
|
@ -19,9 +19,14 @@ html lang="en"
|
||||||
meta name="theme-color" content="#618fc3"
|
meta name="theme-color" content="#618fc3"
|
||||||
meta name="format-detection" content="telephone=no"
|
meta name="format-detection" content="telephone=no"
|
||||||
= csrf_meta_tag()
|
= csrf_meta_tag()
|
||||||
script type="module" src=Routes.static_path(@conn, "/js/app.js") async="async"
|
|
||||||
|
= if vite_reload?() do
|
||||||
|
script type="module" src="http://localhost:5173/@vite/client"
|
||||||
|
script type="module" src="http://localhost:5173/js/app.js"
|
||||||
|
- else
|
||||||
|
script type="text/javascript" src=Routes.static_path(@conn, "/js/app.js") async="async"
|
||||||
= render PhilomenaWeb.LayoutView, "_opengraph.html", assigns
|
= render PhilomenaWeb.LayoutView, "_opengraph.html", assigns
|
||||||
body data-theme=theme_name(@current_user)
|
body data-theme=theme_name(@current_user) data-vite-reload=to_string(vite_reload?())
|
||||||
= render PhilomenaWeb.LayoutView, "_burger.html", assigns
|
= render PhilomenaWeb.LayoutView, "_burger.html", assigns
|
||||||
#container class=container_class(@current_user)
|
#container class=container_class(@current_user)
|
||||||
= render PhilomenaWeb.LayoutView, "_header.html", assigns
|
= render PhilomenaWeb.LayoutView, "_header.html", assigns
|
||||||
|
|
|
@ -22,6 +22,10 @@ defmodule PhilomenaWeb.LayoutView do
|
||||||
Application.get_env(:philomena, :cdn_host)
|
Application.get_env(:philomena, :cdn_host)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def vite_reload? do
|
||||||
|
Application.get_env(:philomena, :vite_reload)
|
||||||
|
end
|
||||||
|
|
||||||
defp ignored_tag_list(nil), do: []
|
defp ignored_tag_list(nil), do: []
|
||||||
defp ignored_tag_list([]), do: []
|
defp ignored_tag_list([]), do: []
|
||||||
defp ignored_tag_list([{tag, _body, _dnp_entries}]), do: [tag.id]
|
defp ignored_tag_list([{tag, _body, _dnp_entries}]), do: [tag.id]
|
||||||
|
|
Loading…
Reference in a new issue