Skip to content

Instantly share code, notes, and snippets.

@scrogson
Forked from ciastek/README
Last active March 13, 2020 13:56
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save scrogson/e72f40c3c8e83c16c4b8 to your computer and use it in GitHub Desktop.
Save scrogson/e72f40c3c8e83c16c4b8 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) remove Bootstrap from web/static/css/app.css
4) rename web/static/css/app.css to web/static/css/app.scss
5) 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 = {
plugins: {
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
}
},
copycat: {
"fonts": ["node_modules/bootstrap-sass/assets/fonts/bootstrap"] // copy node_modules/bootstrap-sass/assets/fonts/bootstrap/* to priv/static/fonts/
}
},
modules: {
autoRequire: {
"js/app.js": [
"bootstrap-sass", // require bootstrap-sass' JavaScript globally
"web/static/js/app"
]
}
},
npm: {
enabled: true,
whitelist: ["phoenix", "phoenix_html", "jquery", "bootstrap-sass"], // pull jquery and bootstrap-sass in as front-end assets
globals: { // bootstrap-sass' JavaScript requires both '$' and 'jQuery' in global scope
$: 'jquery',
jQuery: 'jquery'
}
}
}
npm install --save bootstrap-sass sass-brunch jquery copycat-brunch
@brayhoward
Copy link

Can I ask what version of brunch did you have this working with? I'm trying to accomplish the same thing but to no avail. Right now I have all the asset files I need copied into web/static/vendor, which works but feels wrong.

@DennisKo
Copy link

DennisKo commented Jul 7, 2016

I had to to adjust the sass plugin part to:

  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
        }
      }  

@raysegantii
Copy link

@eproxus
Copy link

eproxus commented Feb 28, 2017

@StevenXL
Copy link

StevenXL commented May 5, 2017

When I run this, I get an error telling me that the top-level object in brunch-config.js must have a property files. How are you guys getting this brunch-config.js to run without that?

At this link: http://brunch.io/docs/config#-files- I see the following text: Required, object: files configures handling of application files: which compiler would be used on which file, what name should output file have etc. Any paths specified here must be listed in paths.watched as described above, for building.

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