calypso

calypso

Hello everyone
I would like to run my react app, which is built with webpack. Everything works fine.
But in the app.html.eex, I need to hardcode to css filename, which contains the contenthash generated by webpack. This contenthash can change and therefore I need to wildcard this to main.*.css.
Is this possible and if yes, how?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Test · Phoenix Framework</title>
    <script defer type="text/javascript" src="<%= Routes.static_path(@conn, "/main.js") %>"></script>
    <link rel="stylesheet" href="<%= Routes.static_path(@conn, "/main.68fc705c4c27d56f9522.css") %>"/>
  </head>
  <body>
  </body>
</html>

Best,
Calypso

Showing Posts 1 to 3

kokolegorille

kokolegorille

Are You using your own webpack outside of Phoenix?

This should be managed with mix phx.digest and You shouldn’t need to know the hash.

calypso

calypso OP

Thanks for the reply!

I’m using a custom webpack.config.ts, which is located in assets folder. Consequently, I configured in my dev.exs

config :app_web, AppWeb.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: [
    node: [
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch",
      "--watch-options-stdin",
      "--config",
      "webpack.dev.config.ts",
      cd: Path.expand("../apps/app_web/assets", __DIR__)
    ]
  ]

In the plugins section of the webpack.config.ts we see how the name of the .css is generated. Of course I can just change that to a static filename, that never changes like style.css. Then of course it is easy to load that file in the app.html.eex.

plugins: [
    new HtmlWebpackPlugin({
      template: "src/index.html",
    }),
    new HotModuleReplacementPlugin(),
    new MiniCssExtractPlugin({
        filename: "[name].[contenthash].css"
    }),
  ]

I do not quite get now mix phx.digest comes into play.

kokolegorille

kokolegorille

$ mix help phx.digest

                                 mix phx.digest                                 

Digests and compresses static files.

    mix phx.digest
    mix phx.digest priv/static -o /www/public

The first argument is the path where the static files are located. The -o
option indicates the path that will be used to save the digested and compressed
files.

If no path is given, it will use priv/static as the input and output path.

The output folder will contain:

  • the original file
  • the file compressed with gzip
  • a file containing the original file name and its digest
  • a compressed file containing the file name and its digest
  • a cache manifest file

Example of generated files:

  • app.js
  • app.js.gz
  • app-eb0a5b9302e8d32828d8a73f137cc8f0.js
  • app-eb0a5b9302e8d32828d8a73f137cc8f0.js.gz
  • cache_manifest.json
— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews