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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
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
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
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
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews