Coder Social home page Coder Social logo

goldibex / plugin-scss Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kevcjones/plugin-scss

0.0 2.0 0.0 95 KB

A SystemJS plugin which will convert sass and return it inline to allow use for any purpose

License: MIT License

JavaScript 90.54% HTML 7.62% CSS 1.84%

plugin-scss's Introduction

plugin-scss

Build Status devDependency Status

At a Glance

Originally forked from plugin-sass

SystemJS SCSS loader plugin. Can easily be installed with jspm package manager.

$ jspm install scss

The decision that it was unlikely that plugin-sass team would ever merge our changes back into the plugin-sass. They have a fundamental differece in use. Plugin-sass is cleaner if all you want to do is load your styles into the head block. However we had a very different use case.

We wanted to transpile our .scss content and return the css as a string so that we could inject it where ever we please. In particular, we wanted to inject into Angular 2's styles decorator.

Using it looks like this in its various forms :

System.import('./style.scss!').then(function(css){
  //inject css in head?
  //pass css into angular2 @component styles tag [up to you]
});

or synchronously

import styles from './style.scss!';
//styles will contain your css ready again for what you need

You can also use the older syntax , known as the indented syntax (or sometimes just "Sass")

System.import('./style.sass!scss').then(function(css){
  //inject your css anywhere you need
});

Compile Targets

Style

By default, plugin-scss does NOT inject compiled css into a <style> tag in the <head>. It instead returns your css as a string. Use plugin-sass if you need this behaviour.

Strings for angular 2

As mentioned above - plugin-scss was a modification of the original plugin specifically because we needed a string that was for use in the @component decorator. It was different enough to feel like a new plugin.

import styles from './style.scss!';

@Component({
    template: '...',
    styles: [styles]
})

SASS options

To add SASS options

sassPluginOptions: {
  "sassOptions": {

  }
}

Importing from jspm

You can import scss files from jspm packages from within scss files using the jspm: prefix. For example, if you have jspm installed twbs/bootstrap-sass:

@import 'jspm:bootstrap-sass/assets/stylesheets/bootstrap';

Bundling using JSPM/SystemJS

We've work on the bundle support, this was where most of the work was done when extending from plugin-sass. Fundamentally, we didn't need to write into the bundle in a special way to inject the css into head. So instead, we used the hooks for translate and fetch to work very similarly to the normal 'inject' route in browser.

Testing the plugin

$ npm install -g gulp
...
$ npm install
...
$ jspm install

Now you can test runtime compilation

$ gulp test:runtime

bundling

$ gulp test:bundle

or static bundling

$ gulp test:bundleStatic

After that open http://localhost:3000 in the browser of your choice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.