TrevorHinesley

TrevorHinesley

Setting up a bootstrap template in Phoenix

Hi everyone!

I’m a long-time Rails programmer and have been dabbling in Elixir/Phoenix. Loving it!

I just downloaded the Argon dashboard by Creative Tim and am trying to get it hooked up a new Phoenix application. Here’s where I’m stuck… following the Quick Start docs, I’ve moved a bunch of their files into my assets directory. Here’s the structure:

assets
  -> css
    -> theme
      -> bootstrap
      -> core
      -> custom
      -> argon.scss
    -> app.scss
    -> phoenix.scss
  -> js
    -> theme
      -> argon.min.js
    -> app.js
    -> socket.js
  -> node_modules
  -> static
  -> vendor
    -> @fortawesome
    -> anchor-js
    ... etc ...

In the assets/vendor folder, I’ve put everything from the dashboard’s own vendor folder, and removed anything wasn’t a compiled/bundled/minified js/css file.

I’m trying to use brunch’s config to specify the order of some files, but it’s not working properly. Here’s my config:

exports.config = {
  // See http://brunch.io/#documentation for docs.
  files: {
    javascripts: {
      joinTo: "js/app.js",

      // To use a separate vendor.js bundle, specify two files path
      // http://brunch.io/docs/config#-files-
      // joinTo: {
      //   "js/app.js": /^js/,
      //   "js/vendor.js": /^(?!js)/
      // }
      //
      // To change the order of concatenation of files, explicitly mention here
      order: {
        before: [
          "vendor/jquery/dist/jquery.min.js",
          "vendor/bootstrap/dist/js/bootstrap.bundle.min.js",
          "js/theme/argon.min.js",
        ],
        after: [
          "js/app.js",
        ],
      }
    },
    stylesheets: {
      joinTo: "css/app.css",

      order: {
        before: [
          "vendor/nucleo/css/nucleo.min.css",
          "vendor/@fortawesome/fontawesome-free/css/all.min.css",
          "css/theme/argon.scss",
        ],
        after: [
          "css/app.scss",
        ],
      }
    },
    templates: {
      joinTo: "js/app.js"
    }
  },

  conventions: {
    // This option sets where we should place non-css and non-js assets in.
    // By default, we set this to "/assets/static". Files in this directory
    // will be copied to `paths.public`, which is "priv/static" by default.
    assets: /^(static)/
  },

  // Phoenix paths configuration
  paths: {
    // Dependencies and current project directories to watch
    watched: ["static", "css", "js", "vendor"],
    // Where to compile files to
    public: "../priv/static"
  },

  // Configure your plugins
  plugins: {
    babel: {
      // Do not use ES6 compiler in vendor code
      ignore: [/vendor/]
    },
    sass: {
      mode: "native", // set to 'native' to force libsass
      options: {
        precision: 8 // Minimum precision required by bootstrap
      }
    }
  },

  modules: {
    autoRequire: {
      "js/app.js": ["js/app"]
    }
  },

  npm: {
    enabled: true
  }
};

The problem is, the js before/after options don’t seem to be working, or at least vendor files are ALWAYS after everything. If I look at the app.js.map that’s bundled by brunch, here’s the sources array:

"sources":["js/theme/argon.min.js","node_modules/phoenix/priv/static/phoenix.js","node_modules/phoenix_html/priv/static/phoenix_html.js","js/socket.js","js/app.js","vendor/jquery/dist/jquery.min.js","vendor/bootstrap/dist/js/bootstrap.bundle.min.js","vendor/@fortawesome/fontawesome-free/js/all.min.js","vendor/@fortawesome/fontawesome-free/js/brands.min.js","vendor/@fortawesome/fontawesome-free/js/fontawesome.min.js","vendor/@fortawesome/fontawesome-free/js/regular.min.js","vendor/@fortawesome/fontawesome-free/js/solid.min.js","vendor/@fortawesome/fontawesome-free/js/v4-shims.min.js","vendor/anchor-js/anchor.min.js","vendor/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js","vendor/chart.js/dist/Chart.bundle.min.js","vendor/clipboard/dist/clipboard.min.js","vendor/headroom.js/dist/jQuery.headroom.min.js","vendor/holderjs/holder.min.js","vendor/jquery-scroll-lock/dist/jquery-scrollLock.min.js","vendor/jquery.scrollbar/jquery.scrollbar.min.js","vendor/nouislider/distribute/nouislider.min.js","vendor/onscreen/dist/on-screen.umd.min.js"]

As you can see, js/app.js is NOT after everything else (at least not after vendor files).

Any ideas what’s going on here? I’ve already checked out this template porting discussion.

Thanks for any help!

First Post!

TrevorHinesley

TrevorHinesley

I actually think this might be a problem with Brunch. Added an issue here: Map sources are ordered incorrectly · Issue #1830 · brunch/brunch · GitHub

Most Liked

Nicd

Nicd

As Brunch development is sparse and Phoenix is moving to Webpack in the next version, you may also want to look that way.

Last Post!

TrevorHinesley

TrevorHinesley

Did notttt know that. Good plan. Thanks!

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement