Skip to content

Add 'transformContent' option#32

Open
AlexeyAndKartashov wants to merge 3 commits into
at-import:masterfrom
AlexeyAndKartashov:master
Open

Add 'transformContent' option#32
AlexeyAndKartashov wants to merge 3 commits into
at-import:masterfrom
AlexeyAndKartashov:master

Conversation

@AlexeyAndKartashov
Copy link
Copy Markdown

@AlexeyAndKartashov AlexeyAndKartashov commented Apr 28, 2016

I use it for custom url resolver.
Example:

  // ...
    .pipe(gulpSass({
      precision: 10,
      importer: require('node-sass-import-once'),
      importOnce: {
        index: true,
        css: true,
        bower: false,

        /**
         * It's new option
         * 
         * @param {string} filename
         * @param {string} contents
         * @returns {string}
         */
        transformContent: function (filename, contents) {
          return [
            '$__filepath: unquote("'+ filename +'");',
            '@function url($url: null, $args...) {',
            '  @return __url($__filepath, $url);',
            '}',
            contents
          ].join('\n');
        }
      },
      functions: {
        '__url($filepath, $url)': function(filepath, url, done) {
          url = url.getValue();
          filepath = filepath.getValue();

          var resolvedUrl = url;
          /* ...custom url resolve here... */
          done(new sass.types.String('url('+ resolvedUrl +')'));
        },
      }
    }))
  // ...

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant