Giter Club home page Giter Club logo

gulp-systemjs-resolver's Introduction

NPM

gulp-systemjs-resolver

Unix-like Build Status Windows Build Status npm version npm dependencies

My Sass Import resolver using systemjs gulp plugin

Install

$ npm install --save-dev gulp-systemjs-resolver

Usage

var gulp = require('gulp');
var sassResolver = require('gulp-systemjs-resolver');

gulp.task('sass', function () {
	return gulp.src('src/file.scss')
		.pipe(sassResolver({systemConfig: './config.js'}))
		.pipe(gulp.dest('dist'));
});

I personally in my project use jspm and configure the package this way for bourbon:

{
  "jspm": {
    "dependencies": {
      "bourbon": "github:thoughtbot/bourbon@^4.2.3"
    },
    "overrides": {
      "github:thoughtbot/[email protected]": {
        "directories": {
          "lib": "bourbon-v4.2.3"
        }
      }
    }
  }
}

Then in your scss file, you can import like:

@import "~bourbon/_bourbon.scss"; //Import bourbon file
@import "./variable.scss"; // Import local file

or

var gulp = require('gulp');
var sass = require('gulp-sass');
var sassResolver = require('gulp-systemjs-resolver');

var includePaths = [];

gulp.task('sass', function () {
	return gulp.src('src/file.scss')
		.pipe(sassResolver({systemConfig: './config.js', includePaths: includePaths}))
		.pipe(sass({includePaths: includePaths}))
		.pipe(gulp.dest('dist'));
});

and

/* @importPath '~bourbon' */
@import "_bourbon.scss"; //Import bourbon file
@import "./variable.scss"; // Import local file

API

systemjsResolver(options)

options

systemConfig

Type: string
Default: ``

This is the path to the SystemJs config file for example ./config.js

includePaths

Type: Array
Default: []

This is the original includePaths which will be passed to sass plugin

License

MIT © Clément Patout

gulp-systemjs-resolver's People

Contributors

clempat avatar jstri avatar rkrzewski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gulp-systemjs-resolver's Issues

Failure on repeated builds

The resolver works great during first processing of scss sources, but when it is invoked from a gulp.watch for the second and consecutive time, it fails with the following exception:

TypeError: Incorrect configuration order. The baseURL must be configured with the first SystemJS.config call.
    at SystemJSNodeLoader.SystemJSLoader.config (/home/rafal/workspaces/web/gulp-jspm-sbt/node_modules/gulp-systemjs-resolver/node_modules/systemjs/dist/system.src.js:1753:13)
    at eval (eval at <anonymous> (/home/rafal/workspaces/web/gulp-jspm-sbt/node_modules/gulp-systemjs-resolver/index.js:26:11), <anonymous>:1:8)
    at module.exports (/home/rafal/workspaces/web/gulp-jspm-sbt/node_modules/gulp-systemjs-resolver/index.js:26:3)
    at Gulp.<anonymous> (/home/rafal/workspaces/web/gulp-jspm-sbt/gulpfile.js:110:13)

My test project is hosted on Bitbucket: https://bitbucket.org/rkrzewski/gulp-jspm-sbt

As far as I can tell, the problem arises because SystemJS is intialized on the first invocation of
eval(fs.readFileSync(options.systemConfig, 'utf8')); and there is no obvious way to change or reset this configuration afterwards. A possible workaround would be introduced a guard variable that would ensure that SystemJS is initialized only once during node process lifetime. SystemJS config is not changed too often, so the requirement to restart resident gulp process to reload changes is not too onerous.

On the other hand, if there's something wrong with my gulpfile, I'm all ears :)

Manage to import paths

In this way the idea is to have in the original file.

/* @importPath '~bourbon' */
@import '_bourbon.scss';

then write in includePaths variable:
../jspm_packages/github/thoughtbot/[email protected]

Windows issue

Under windows i get this error:


>> @import "../../../../../../C:/Users/dob/Development/static/myproj_q
   ^

    column: 1
    line: 3
    file: C:/Users/dob/Development/static/myproj_questionaire_2016/src/application.scss
    status: 1
    messageFormatted: src\application.scss
Error: File to import not found or unreadable: ../../../../../../C:/Users/dob/Development/static/myproj_questionaire_2016/jspm_packages/github/angular/[email protected]/angular-material.scss
       Parent style sheet: C:/Users/dob/Development/static/myproj_questionaire_2016/src/application.scss
        on line 3 of src/application.scss
>> @import "../../../../../../C:/Users/dob/Development/static/myproj_q
   ^

    messageOriginal: File to import not found or unreadable: ../../../../../../C:/Users/dob/Development/static/myproj_questionaire_2016/jspm_packages/github/angular/[email protected]/angular-material.scss

The same project runs under MacOSX without any problems.

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.