PeterDavidCarter

PeterDavidCarter

The helpers in my template result in this code when I view the source of my site while it’s serving at localhost:

<script src="/js/app.js"></script>
<script src="/js/nav.js"></script>

The local file structure is …

/assets
  /js/
    app.js
    nav.js 

But while the app.js file serves fine, the nav.js shows a 404 in the developer console. Why is the Phoenix server refusing to serve this file and how do I fix it?

Showing Posts 1 to 10

OvermindDL1

OvermindDL1

Uh, but Phoenix doesn’t host out of assets by default, it hosts out of ./priv/static by default, do you have a nav.js in there?

Whatever build system you use at the very least either needs to concat nav into app (the default one that phoenix uses, brunch, does that automatically) or you need to have it copy nav to the output priv/static directory.

PeterDavidCarter

PeterDavidCarter OP

My brunch file has

javascripts: {
      joinTo: {
        'app.js': /^js/,
        'nav.js': /^js\/navigation/

The priv subdirectories don’t actually have the app.js file, which is what’s confusing me even more.

I’m currently just using the default Phoenix development settings. I don’t dare push to production without being sure.

OvermindDL1

OvermindDL1

This means that everything in the js/navigation directory in assets will be compiled to nav.js, but your listing had no such directory, so that does nothing. Currently app.js is taking in everything under js, so nav is being put into it too.

Should be in something like priv/static/js/app.js or so, and only once you either start the dev server or so.

PeterDavidCarter

PeterDavidCarter OP

My apologies for not including full details of my solution:

/navigation
  /master.js

Exists in my /js directory.

I can remove the js subdirectories, but at the moment I’m just testing that brunch works and I wanted to see master.js compiled to nav.js but I’m not seeing that.

OvermindDL1

OvermindDL1

I doubt it still would, the app.js is grabbing everything under js, including the things in the navigation folder, so when the nav.js entry is hit there is nothing left for it to take. Fixup the app regex to exclude the navigation directory to start. :slight_smile:

PeterDavidCarter

PeterDavidCarter OP

Wow. I wouldn’t have thought of it as ‘grabbing everything’ in the sense of removing stuff (would have thought it works more cp than mv). I thought it was just spidering the directories. I have a few things I need to do right now but if your solution works I’ll be very impressed! :blush:

OvermindDL1

OvermindDL1

Brunch is powerful, but it does have a few specific things to be aware of, all in its documentation though. :slight_smile:

PeterDavidCarter

PeterDavidCarter OP

Yeah. When you’re unemployed and trying to put a showcase site together you tend to go with getting functionality up first. I did read some of the documentation but urg, sometimes it’s difficult to juggle stuff :/. Will have more of a look tomorrow.

PeterDavidCarter

PeterDavidCarter OP

Ok, I now have this:

javascripts: {
      joinTo: {
        'nav.js': /^js\/navigation/

in my brunch file, and have even removed all of the import statements in my app.js file, but it’s still compiling all the JavaScript into a single app.js file :neutral_face::expressionless: :neutral_face:

peerreynders

peerreynders

I think one of the issues you are battling is that the second pattern covers files that are already included in the first pattern. The easiest way to deal with that is to move everything that is under /js but not in /js/navigation into a separate folder like /js/app. Then rewrite the configuration as:

      joinTo: {
        'app.js': /^js\/app/,
        'nav.js': /^js\/navigation/

According to documentation that should give you two separate files.

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews