How to use foundation 6 with angular cli.I tried with plain scss but was unable to proceed with foundation 6 scss.How should I proceed with this. Thanks in advance.
2 Answers
Create a new "sassy" Project with the Angular CLI:
ng new sassy-project --style=sass
Then install Foundation Sites via NPM:
npm install foundation-sites --save
Finally import the Foundation SASS-File in the projects styles.scss file:
@import "../node_modules/foundation-sites/assets/foundation";
For more Details: https://github.com/angular/angular-cli#css-preprocessor-integration

- 4,872
- 2
- 28
- 25
-
`ng new` documentation. https://github.com/angular/angular-cli/blob/master/docs/documentation/new.md – Gavin Bruce Mar 22 '17 at 22:32
-
1Thanks! I was including ~/scss/foundation.scss, including ~/assets/foundation.scss instead solved my issue! – Taylor Ackley May 05 '17 at 21:05
-
Thank you! You also could be interested by using the settings file. To do so, copy node_modules/foundation-sites/scss/settings/_settings.scss into assets/styles/foundation-settings.scss, fix the path of util/util import in your copied file to @import '~foundation-sites/scss/util/util'; instead and import your settings *before* your main foundation file in styles.scss ... – Sylvain Aug 19 '17 at 02:59
Do you use the angular cli or the webpack starter package?
With webpack it's very straightforward to implement foundation. At the moment i'm using Angular2 Webpack Starter.
- Install foundation-sites via npm
Import foundation-sites in your vendor.ts file. Like so:
import 'foundation-sites';
Import foundation scss file in your app.scss like this:
@import '~foundation-sites/scss/foundation'
Include your preferred mixins.
@include foundation-global-styles; @include foundation-typography;
Angular CLI (without webpack)
To include external sass files in your project, you have to change the angular cli build file. The angular cli is based on the ember cli and uses broccoli to compile your assets. There is a excellent article about this on the codementor website.
In short you have to install extra node_modules for broccoli and change your angular-cli-build.js file.
Run the following command to install the extra node_modules:
npm i broccoli-sass broccoli-merge-trees lodash glob broccoli-postcss postcss-cssnext cssnano --save
For reference here is my angular-cli-build.js
const Angular2App = require('angular-cli/lib/broccoli/angular2-app');
const compileSass = require('broccoli-sass');
const compileCSS = require('broccoli-postcss');
const cssnext = require('postcss-cssnext');
const cssnano = require('cssnano');
const mergeTrees = require('broccoli-merge-trees');
const _ = require('lodash');
const glob = require('glob');
var options = {
plugins: [
{
module: cssnext,
options: {
browsers: ['> 1%'],
warnForDuplicates: false
}
},
{
module: cssnano,
options: {
safe: true,
sourcemap: true
}
}
]
};
module.exports = function (defaults) {
let appTree = new Angular2App(defaults, {
sassCompiler: {
cacheExclude: [/\/_[^\/]+$/],
includePaths: [
'node_modules/foundation-sites/scss/util/util',
'node_modules/foundation-sites/scss/foundation',
'src/assets/styles'
]
},
vendorNpmFiles: [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'zone.js/dist/**/*.+(js|js.map)',
'es6-shim/es6-shim.js',
'reflect-metadata/**/*.+(js|js.map)',
'rxjs/**/*.+(js|js.map)',
'@angular/**/*.+(js|js.map)'
]
});
let sass = mergeTrees(_.map(glob.sync('src/**/*.scss'), function (sassFile) {
sassFile = sassFile.replace('src/', '');
return compileSass(['src'], sassFile, sassFile.replace(/.scss$/, '.css'));
}));
let css = compileCSS(sass, options);
return mergeTrees([appTree, sass, css], { overwrite: true });
};
In your .scss file you can include foundation sass file like this:
@import "node_modules/foundation-sites/scss/foundation";

- 1,463
- 15
- 23
-
is it better to use foundation-apps instead of foundation-sites when using with angular 2 apps – user93 Aug 11 '16 at 04:36
-
Foundation Apps 1 is based on Angular 1.x. The work for Foundation for Apps 2 will started soon when Angular 2.x is reaching a stable version. There is a thread on the Foundation forms about this: [link](http://foundation.zurb.com/forum/posts/39392-angular-2-and-foundation-6) So at the moment i recommend using foundation sites, and activate the flexbox mode. With flexbox you can easily create a app like feeling. More about the flexbox mode here: [link](http://foundation.zurb.com/sites/docs/flexbox.html) – Frank Spin Aug 11 '16 at 09:15
-
@FrankSpin How can I import specific Foundation Js modules in vendor.ts ? – Abudayah Jun 27 '18 at 10:31