Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phoenix - no route found for GET /static/js/some.js

I am migrating my rails application to phoenix framework.

I added some javascript (say some.js) and css files to web/static/js and web/static/css dir.

<%= static_path(@conn, "/js/some.js") %> in the front page page/index.html.eexdidn't work. It raised the exception (dev env):

Phoenix.Router.NoRouteError at GET /static/js/some.js
no route found for GET /static/js/some.js (VisualTrader.Router)

If I copied some.js to priv/static/js dir, it worked. So what I missed? I thought the assets pipeline worked like the one in rails, which auto precompiled resources.

Below list my phoenix framework environments:

  • Elixir version

    elixir -v
    
    Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
    
    Elixir 1.3.0-dev (187f4f8)
    
  • Phoenix version

    defp deps do
       [{:phoenix, "~> 1.1.2"},
       ...
    
like image 494
Jack Tang Avatar asked Mar 09 '16 16:03

Jack Tang


1 Answers

If you want to include the Javascript File to be precompiled you'd need to add the following line of code.

Add your Javascript file in web/static/js directory.

In web/static/js/app.js include your file

import "./some-file"
like image 50
Ronak Jain Avatar answered Sep 24 '22 19:09

Ronak Jain