Sitemap
AJ Robertson

AJ Robertson

React Native instructor & computer programmer at @infinite_red.

Elixir Phoenix Framework and Sass

2 min readNov 3, 2015

Edit: Since the writing of this article, we at http://infinite.red, have developed new best practices. If you are starting a new Elixir project or are just trying to get Sass to work, take a look at our Phoenix Base project. In this project we have replace Brunch with Webpack and I highly recommend you do the same. From my experience, Webpack works better with React and is easier to work with. If you have questions, please reach out to me on twitter, @codeithuman.

Elixir Phoenix Framework supports CSS and SCSS out of the box, but getting Phoenix setup with SASS (.sass) can be tricky to figure out, especially with little knowledge of the Phoenix ecosystem.

By default, Phoenix uses Brunch.io for asset management. This means all JavaScript, stylesheets and other files in your project’s “/web/static/” directory are managed by Brunch. Therefore, we will be using Brunch to add .sass file support to our Phoenix application.

Get AJ Robertson’s stories in your inbox

Join Medium for free to get updates from this writer.

Adding SASS support to a Phoenix application is easy. We will be using sass-brunch. Open the terminal, navigate to your project’s root directory and run the following command:

npm i -S sass-brunch

This command uses Node Package Manager (npm) to install (i) and save (-S) sass-brunch to your Phoenix application’s package.json file. Brunch will read the package.json file and knows to use sass-brunch. Your Phoenix application now supports .sass files, no extra configuration needed!

You can put .sass files in the “/web/static/css/” directory and they will be included in your application styles, no CSS “import” statements needed. You can even add subdirectories, like “/static/css/homepage/home.sass”, and all files will be included.

At this point you still have the app.css file. Feel free to delete, convert it to .sass or leave this file as is. The app.css is not mandatory for a Phoenix application.

In the comments, let me know how you found this article helpful. If you have any further questions, please feel free to reach out to me, @ajrob27, on Medium, Twitter or in the Elixir Community Slack.

--

--

AJ Robertson
AJ Robertson

Written by AJ Robertson

React Native instructor & computer programmer at @infinite_red.