Skip to content

Instantly share code, notes, and snippets.

@raysegantii
Forked from scrogson/README
Last active June 3, 2020 21:24
Show Gist options
  • Save raysegantii/c1bd7e2ba55413a0c130f7316b5c7a13 to your computer and use it in GitHub Desktop.
Save raysegantii/c1bd7e2ba55413a0c130f7316b5c7a13 to your computer and use it in GitHub Desktop.
Use bootstrap-sass npm package with Phoenix's brunch
  1. install npm packages
  2. update brunch-config.js
  3. rename web/static/css/app.css to web/static/css/app.scss
  4. update web/static/css/app.scss
$icon-font-path: "/fonts/"; /* use fonts from priv/static/fonts/ */
@import "bootstrap"; /* imports node_modules/bootstrap-sass/assets/stylesheets/_bootstrap.scss */
exports.config = {
// See http://brunch.io/#documentation for docs.
files: {
javascripts: {
joinTo: "js/app.js"
},
stylesheets: {
joinTo: "css/app.css",
order: {
after: ["web/static/css/app.scss"] // concat app.css last
}
},
templates: {
joinTo: "js/app.js"
}
},
conventions: {
assets: /^(web\/static\/assets)/
},
// Phoenix paths configuration
paths: {
// Dependencies and current project directories to watch
watched: [
"web/static",
"test/static"
],
// Where to compile files to
public: "priv/static"
},
plugins: {
babel: {
ignore: [/web\/static\/vendor/]
},
copycat: {
"fonts": ["node_modules/bootstrap-sass/assets/fonts/bootstrap"] // copy node_modules/bootstrap-sass/assets/fonts/bootstrap/* to priv/static/fonts/
},
sass: {
options: {
includePaths: ["node_modules/bootstrap-sass/assets/stylesheets"], // tell sass-brunch where to look for files to @import
precision: 8 // minimum precision required by bootstrap-sass
}
}
},
modules: {
autoRequire: {
"js/app.js": ["web/static/js/app"]
}
},
npm: {
enabled: true,
globals: { // bootstrap-sass' JavaScript requires both '$' and 'jQuery' in global scope
$: 'jquery',
jQuery: 'jquery',
bootstrap: 'bootstrap-sass' // require bootstrap-sass' JavaScript globally
}
}
}
npm install --save-dev sass-brunch copycat-brunch
npm install --save bootstrap-sass jquery
@raysegantii
Copy link
Author

Updates:

  1. Latest brunch doesn't need whitelist, https://github.com/brunch/brunch/blob/master/CHANGELOG.md#brunch-22-jan-22-2016
  2. Include bootstrap globally as example, otherwise brunch doesn't require it, https://elixirforum.com/t/bootstrap-show-hide-operations-do-nothing-in-phoenix-app/1212/2

@divyanshu707
Copy link

Thanks. Works perfectly !!

@duksis
Copy link

duksis commented Jan 19, 2017

thanks!

@StevenXL
Copy link

StevenXL commented May 5, 2017

Thanks for this. I've been scratching my head on the least painful way to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment