Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using foundation 6 scss with angular 2 cli

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.

like image 658
user93 Avatar asked Aug 10 '16 06:08

user93


People also ask

How do I use SCSs in angular?

Let’s get into it! When creating a new Angular app using the ng new app-name command, the CLI will ask you “ Which stylesheet format would you like to use? ” — select SCSS. When choosing this option when creating a new project, the main things the CLI does is the following:

How do I get the angular CLI to generate CSS files?

To get the CLI to generate .scss files (or .sass / .less) is an easy matter. You can also set the --style flag with the following: If you’ve already created your Angular CLI app with the default .css files, it will take a bit more work to convert it over.

How to use Sass with angular CLI?

Using Sass with the Angular CLI 1 Starting an Angular CLI Project with Sass. Normally, when we run ng new my-app, our app will have .css files. ... 2 Converting a Current App to Sass. ... 3 Using Sass Imports. ... 4 Importing Sass Files Into Angular Components. ... 5 Sass Include Paths. ... 6 Using Bootstrap Sass Files. ... 7 Conclusion. ...

How to create SCSS files instead of CSS when creating components?

The other thing you need to do is update your CLI configuration to create SCSS files instead of CSS files when you create new components. There are two ways to do this — using the CLI command or adding the reference manually. To use the command type the following into your terminal: ng config schematics.@schematics/angular:component.styleext scss


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

like image 172
Blank Avatar answered Oct 20 '22 10:10

Blank


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.

  1. Install foundation-sites via npm
  2. Import foundation-sites in your vendor.ts file. Like so:

    import 'foundation-sites';

  3. Import foundation scss file in your app.scss like this:

    @import '~foundation-sites/scss/foundation'

  4. 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";
like image 22
Frank Spin Avatar answered Oct 20 '22 08:10

Frank Spin