How to use SASS/SCSS with Phoenix framework?

NoDisplayName picture NoDisplayName · Aug 13, 2015 · Viewed 7.9k times · Source

Is there a way to use sass/scss for stylesheets when using Phoenix Framework? And if there is, then how ?

Answer

Lenin Raj Rajasekaran picture Lenin Raj Rajasekaran · Aug 13, 2015

Phoenix framework uses brunch for the asset pipeline.

From the docs:

Instead of implementing its own asset pipeline, Phoenix uses Brunch, a fast and developer-friendly asset build tool. Phoenix comes with a default configuration for Brunch and it will work out of the box, but it is very easy to bend it to our needs, add support for various script and style languages, like CoffeeScript, TypeScript, or LESS.

To add support for SASS, add 'sass-brunch' in your package.json in the project root as:

{
  "repository": {
  },
  "dependencies": {
    "brunch": "^1.8.1",
    "babel-brunch": "^5.1.1",
    "clean-css-brunch": ">= 1.0 < 1.8",
    "css-brunch": ">= 1.0 < 1.8",
    "javascript-brunch": ">= 1.0 < 1.8",
    "sass-brunch": "^1.8.10",
    "uglify-js-brunch": ">= 1.0 < 1.8"
  }
}

Then run npm install.

Phoenix framework also supports asset management without brunch as the default.

While creating a new project:

mix phoenix.new --no-brunch my_project

will create a project without brunch configuration. You need to setup a system that can copy the built assets into priv/static/ and also watch your source files to make automatic compilation on every change. Read the docs for more info.