Coder Social home page Coder Social logo

postcss-assets's Introduction

postcss-assets

PostCSS Assets is an asset manager for CSS. It isolates stylesheets from environmental changes, gets image sizes and inlines files.

Unix Build Status Windows Build Status Coverage

Table of contents

Terms of use

By using this project or its source code, for any purpose and in any shape or form, you grant your implicit agreement to all the following statements:

  • You condemn Russia and its military aggression against Ukraine
  • You recognize that Russia is an occupant that unlawfully invaded a sovereign state
  • You support Ukraine's territorial integrity, including its claims over temporarily occupied territories of Crimea and Donbas
  • You reject false narratives perpetuated by Russian state propaganda

Glory to Ukraine! 🇺🇦

Installation

npm install postcss-assets --save-dev

Usage

gulp.task('assets', function () {
  var postcss = require('gulp-postcss');
  var assets  = require('postcss-assets');

  return gulp.src('source/*.css')
    .pipe(postcss([assets({
      loadPaths: ['images/']
    })]))
    .pipe(gulp.dest('build/'));
});
var assets  = require('postcss-assets');

grunt.initConfig({
  postcss: {
    options: {
      processors: [
        assets({
          loadPaths: ['images/']
        })
      ]
    },
    dist: { src: 'build/*.css' }
  },
});

Note: all of the listed options below are parameters for the assets object, not the top level postcss options object.

URL resolution

These options isolate stylesheets from environmental changes.

Load paths

To make PostCSS Assets search for files in specific directories, define load paths:

var options = {
  loadPaths: ['fonts/', 'media/patterns/', 'images/']
};

Example:

body {
  background: resolve('foobar.jpg');
  background: resolve('icons/baz.png');
}

PostCSS Assets would look for the files relative to the source file, then in load paths, then in the base path. If it succeed, it would resolve a true URL:

body {
  background: url('/media/patterns/foobar.jpg');
  background: url('/images/icons/baz.png');
}

Base path

If the root directory of your site is not where you execute PostCSS Assets, correct it:

var options = {
  basePath: 'source/'
};

PostCSS Assets would treat source directory as / for all URLs and load paths would be relative to it.

Base URL

If the URL of your base path is not /, correct it:

var options = {
  baseUrl: 'http://example.com/wp-content/themes/'
};

Relative paths

To make resolved paths relative to the input file, set a flag:

var options = {
  relative: true
};

To relate to a particular directory, set it as a string:

var options = {
  relative: 'assets/css'
};

Cachebuster

PostCSS Assets can bust assets cache:

var options = {
  cachebuster: true
};

Example:

body {
  background: resolve('/images/icons/baz.png');
}

PostCSS Assets will change urls depending on asset’s modification date:

body {
  background: url('/images/icons/baz.png?14a931c501f');
}

To define a custom cachebuster pass a function as an option:

var options = {
  cachebuster: function (filePath, urlPathname) {
    return fs.statSync(filePath).mtime.getTime().toString(16);
  }
};

If the returned value is falsy, no cache busting is done for the asset.

If the returned value is an object the values of pathname and/or query are used to generate a cache busted path to the asset.

If the returned value is a string, it is added as a query string.

The returned values for query strings must not include the starting ?.

Busting the cache via path:

var options = {
  cachebuster: function (filePath, urlPathname) {
    var hash = fs.statSync(filePath).mtime.getTime().toString(16);
    return {
      pathname: path.dirname(urlPathname)
        + '/' + path.basename(urlPathname, path.extname(urlPathname))
        + hash + path.extname(urlPathname),
      query: false // you may omit this one
    }
  }
};

Image dimensions

PostCSS Assets calculates dimensions of PNG, JPEG, GIF, SVG and WebP images:

body {
  width: width('images/foobar.png'); /* 320px */
  height: height('images/foobar.png'); /* 240px */
  background-size: size('images/foobar.png'); /* 320px 240px */
}

To correct the dimensions for images with a high density, pass it as a second parameter:

body {
  width: width('images/foobar.png', 2); /* 160px */
  height: height('images/foobar.png', 2); /* 120px */
  background-size: size('images/foobar.png', 2); /* 160px 120px */
}

Inlining files

PostCSS inlines files to a stylesheet in Base64 encoding:

body {
  background: inline('images/foobar.png');
}

SVG files would be inlined unencoded, because then they benefit in size.

Full list of options

Option Description Default
basePath Root directory of the project. .
baseUrl URL of the project when running the web server. /
cachebuster If cache should be busted. Pass a function to define custom busting strategy. false
loadPaths Specific directories to look for the files. []
relative Directory to relate to when resolving URLs. When true, relates to the input file. When false, disables relative URLs. false
cache When true, if the input file not been modifed, use the results before cached. false

postcss-assets's People

Contributors

ai avatar avanes avatar booxood avatar borodean avatar davedx avatar demiazz avatar onigoetz avatar pascalduez avatar uzitech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postcss-assets's Issues

SCSS Flags removed?

Any SCSS files containing a !default or !global, postcss-assets seem to remove them. e.g.

$var: 100 !default;
$foo: "hello" !global;
$something: "bye" !important;

converts to:

$var: 100 ;
$foo: "hello" ;
$something: "bye" !important;

Simple gulp function as follows:

return gulp.src(path.join(contextObject.srcDir, 'style', '**', '*.{scss,css}'))
        .pipe($.postcss([require('postcss-assets')({
            loadPaths: contextObject.cssAssetPaths
        })], { syntax: require('postcss-scss') }))
...
}

The task runs fine and inline of assets work but I want to retain these flags so I am unsure whether this is a postcss-assets bug or there is an option somewhere.

Any ideas? Many thanks!

about the baseUrl

My config:

option: {
  basePath: 'src/',
  baseUrl: '//x.autoimg.cn/www/'
}

My style:

html {
  background: resolve("../img/bg.png");
}

My output:

html {
  background: url('/x.autoimg.cn/www/index/img/bg.png');
}

Expected:

html {
  background: url('//x.autoimg.cn/www/index/img/bg.png');
}

Relative path from current CSS file

When I write

@font-face {
    src: inline("./demi.woff")
}

I expect that it takes file from same dir as CSS files.

You can take CSS file path from decl.source.input.file.

Size functions in @media

I need to use height(image) in media features, but I can't.

.Page--blank {
    @media screen and (min-height: height(image)) {
        background-size: cover;
    }
}
@media screen and (min-height: height(image)) {
    .Page--blank {
        background-size: cover;
    }
}

I have workaround this with variable, but it not obvious:

$imageHeight: height(image);

.Page--blank {
    @media screen and (min-height: $imageHeight) {
        background-size: cover;
    }
}
@media screen and (min-height: 1200px) {
    .Page--blank {
        background-size: cover;
    }
}

image-url() replication

Hi,
In Compass (within Middleman for example) there's a function called image-url() that allows users to specify an image and the system is able to determine not only the location, but also grab the respective "cache-busted" filename as well. So,

url('foo.png')

Would return:

url('/assets/images/foo-398ds09.png')

I didn't see this feature specifically called out in this plugin, but wanted to know if that is something that is available. Thanks!

Module build failed: TypeError: Cannot read property 'relative' of undefined

I ran into this error after upgrading to 4.0.0 with my webpack build:

ERROR in ./~/css-loader!./~/postcss-loader!./~/normalize.css/normalize.css
Module build failed: TypeError: Cannot read property 'relative' of undefined
    at C:\Users\user\Desktop\postcss-assets-4.0.0-error\node_modules\postcss-assets\index.js:32:20
    at LazyResult.run (C:\Users\user\Desktop\postcss-assets-4.0.0-error\node_modules\postcss\lib\lazy-result.js:206:20)
    at C:\Users\user\Desktop\postcss-assets-4.0.0-error\node_modules\postcss\lib\lazy-result.js:120:37
    at LazyResult.asyncTick (C:\Users\user\Desktop\postcss-assets-4.0.0-error\node_modules\postcss\lib\lazy-result.js:134:15)
    at processing.Promise.then._this2.processed (C:\Users\user\Desktop\postcss-assets-4.0.0-error\node_modules\postcss\lib\lazy-result.js:160:20)
    at LazyResult.async (C:\Users\user\Desktop\postcss-assets-4.0.0-error\node_modules\postcss\lib\lazy-result.js:157:27)
    at LazyResult.then (C:\Users\user\Desktop\postcss-assets-4.0.0-error\node_modules\postcss\lib\lazy-result.js:79:21)
    at Object.module.exports (C:\Users\user\Desktop\postcss-assets-4.0.0-error\node_modules\postcss-loader\index.js:47:32)
 @ ./~/normalize.css/normalize.css 4:14-96

To reproduce, simply clone this repo: https://github.com/F21/postcss-assets-4.0.0-error

Then run npm install and npm run build.

bring back "relativeTo" in some form

Hi,

I'm sorry to have to make an issue to ask for a removed feature, but I have a use case were it worked perfectly and I can't get the new way to work.

My environment

  • a java webapp, compiling with the frontend-maven-plugin with gulp
  • the paths must be relative because there is no way to know where it will be deployed in advance
  • gulp-svg2png to create png's out of all my svg's
  • This folder structure
src/main/frontend/          # Source folder
  gulpfile.js
  css/
    file.scss
  images/
    image.svg

src/main/webapp/resources/  # Built folder
  css/
    file.css
  images/
    image.png
    image.svg

My current configuration

var assetsOptions = {
  loadPaths: ["../webapp/resources/images"],
  relativeTo: "../webapp/resources/css",
};
processors.push(require("postcss-assets")(assetsOptions));

So the following css : .Image1 { background: resolve('image.png'); } compiles to .Image1 { background: url('../images/image.png'); }

Updating to 4.0

If I update to 4.0 and update my configuration to

var assetsOptions = {
  loadPaths: ["../webapp/resources/images"],
  relative: true,
};

now, the same css (.Image1 { background: resolve('image.png'); } will compile to .Image1 { background: url('../../webapp/resources/images/image.png'); }

While you could say, that I can change loadPaths to loadPaths: ["images"], this will work for almost all files, but not for svg files converted to png, because they don't exist in src/main/frontend/images.

Do you have an idea how I can support that use case in my project ?

Base64 SVG Please

Only a Base64 data-uri will render in all IE versions. Inlining SVG in a stylesheet, whether raw or url encoded, will NOT render in IE. Chris Coyier is the CSS guru, but that article of his to which you link has always baffled me. The comments in that thread fill in the parts he left out. I would love to use your plug-in, but it isn't very practical unless you base64 all the things. Thanks so much.

Realtive/Base path confusion

Hello,

This isn't so much as an "issue", but not sure where else to put it. I was struggling a bit with using the resolve() function with Gulp and Sass and such.

My folder structure is:

gulpfile.js

public_html/
  assets/
    project/
      css/
      img/

build/
  project/
    css/
    img/

The scss and images are in the build folder. The project folder is client specific. Sometimes we have one CMS install for several sites, so there will be a folder parallel to project folder with a different name but with CSS and JS in. Becuase of this, I can't hardcode the project folder in the gulpfile.

Gulp currently watches the CSS folder for sass changes and compiles it to public_html/assets with the same path. The same is for the images, where they get optimised on their journey over.

I couldn't seem to get the postcss-assets to make a path of /assets/<path>. I could get it to have public_html in the path but not take this off.

My sass is like this:

div {
    background: resolve('../img/bg.png');
}

This then gets compiled with the full path, but back to build (which is outside the public_html - so the image can't be rendered).

My current way of solving this is to compile the scss, put the file in the public_html folder and then postcss that - which seems a bit odd.

Any ideas? Happy to be a guinea pig. I did try every which way I could with all the different settings but couldn't work it out.

I would like to use the resolve function for the cachebusting.

Calling with `assets().postcss`

The Grunt docs say to call this plugin like so:

require('postcss-assets')({}).postcss,

But that doesn't seem to work. Calling without .postcss seems to work for me.

Common PostCSS API

Most of PostCSS plugins works as plugin instead of plugin() if there is no options.

postcss([
    require('autoprefixer-core'),
    require('postcss-nested'),
    require('postcss-mixins'),
    require('postcss-assets')() // ugly
])

I make this behavior by:

module.exports = function (opts) {
    //  work with options
    return function (css) {
        // work with AST
    };
};

module.exports.postcss = function (css) {
    module.exports()(css);
};

Add Travis CI

Travis CI is awesome. You already have everything for it. Just add .travis.yml for node.js and enable repository on travis-ci.org.

TypeError: [object Object] must be a function, did you require() it ? with Webpack 2

Hi there,

First of all, great plugin, I found it really handy to use in a previous gulp based setup, does exactly what it says on the tin!

I seem to be having an issue with it in Webpack 2 though, the error:

'TypeError: [object Object] must be a function, did you require() it ?' referencing '/node_modules/postcss-load-plugins/lib/plugins.js' in the stack trace as the call site of the problem.

I have had no problems with the other postcss modules I use, seems to be either an issue specifically with post-css assets.

Without knowing much about the internals of postcss-load-plugins, as the error suggests it would seem to be expecting a function and not an object.

Is this a known issue or am I doing something wrong?

For reference (parts omitted for brevity):

webpack.config.js

...
module: {
    rules: [
      ...
    {
      test: /\.(sass|scss|css)$/,
      loader: ExtractTextPlugin.extract({
        fallbackLoader: 'style-loader',
        loader: [
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1
            }
          },
          { 
            loader: 'postcss-loader'
          }, 
          {
            loader: 'sass-loader',
            options: {
              includePaths: [
                paths.styles.main
              ]
            }
          }
        ]
      })
    }],
  },
...

postcss.config.js

...
const assets = require('postcss-assets'),
  autoprefixer = require('autoprefixer'),
  cssnano = require('cssnano'),
  inlineSVG = require('postcss-inline-svg'), 
  mqpacker = require('css-mqpacker');

const paths = require('./config/paths'),
  dev = process.env.NODE_ENV === 'development';

module.exports = {
  plugins: [
    assets({
      cacheBuster: true,
      loadPaths: [
        paths.images.main
      ]
    }),
    autoprefixer({
      browsers: 'last 2 versions'
    }),
    inlineSVG({
      path: paths.images.main
    }),
    mqpacker
  ].concat(dev ? [] : [
    cssnano
  ])
}

relative assumes input file path === output file path

when using this in an asset pipeline it often happens that you bundle everything in your css folder into bundle.min.css and in my case the output file is in the root.

assuming I have css/main.css it resolves correctly images/foo.png into ../images/foo.png but this breaks the output bundle.

I would suggest to allow a string to be passed to relative representing the path you want to resolve against.

How about > background-image: inline('mysvgfile.svg', 'fill-color-value');

Thank you for this postcss plugin!
A flexible inline image function was the one thing I truly missed when switching from Ruby SASS with Compass.

Anyway, I was thinking, this function could be really amazing if we would be able to pass a fill-color along so the function find/replaces the fill color in the svg before actually inlining it.
This way we can actually re-use the same svg-file, even if it needs to be in different colors.

You could even allow multiple value's to make multi-colored svg's

value 1 replaces the first occurrence of fill=""
value 2 replaces the second occurrence of fill=""
...

Same could go for stroke values also :)

Gonzales error

If CSS contains url(./nevis-logo-subset.woff) it fails Gonzales

Error: Please check the validity of the CSS block starting from the line #0
    at throwError (/home/ai/Dev/amplifr/front/node_modules/postcss-assets/node_modules/gonzales/lib/gonzales.cssp.node.js:399:15)
    at getFunctionBody (/home/ai/Dev/amplifr/front/node_modules/postcss-assets/node_modules/gonzales/lib/gonzales.cssp.node.js:1233:17)
    at getFunktion (/home/ai/Dev/amplifr/front/node_modules/postcss-assets/node_modules/gonzales/lib/gonzales.cssp.node.js:1212:13)
    at Object.CSSPRules.funktion (/home/ai/Dev/amplifr/front/node_modules/postcss-assets/node_modules/gonzales/lib/gonzales.cssp.node.js:389:65)
    at _getAST (/home/ai/Dev/amplifr/front/node_modules/postcss-assets/node_modules/gonzales/lib/gonzales.cssp.node.js:409:38)
    at exports.srcToCSSP (/home/ai/Dev/amplifr/front/node_modules/postcss-assets/node_modules/gonzales/lib/gonzales.cssp.node.js:2287:16)
    at Object.exports.srcToCSSP (/home/ai/Dev/amplifr/front/node_modules/postcss-assets/node_modules/gonzales/lib/gonzales.cssp.node.js:2292:16)
    at traverse (/home/ai/Dev/amplifr/front/node_modules/postcss-assets/lib/mapFunctions.js:35:23)
    at /home/ai/Dev/amplifr/front/node_modules/postcss-assets/lib/mapFunctions.js:56:16
    at Array.map (native)

But it is a valid CSS.

Wrong path in multi-level dir

Hi,
I got a same path with using resolve in different level directories. e.g.

app/
  img/
    a.png
  css/
    x.css
    folder/
      y.css

Use the same code in x.css and y.css:

.someClass {
    background: resolve('a.png');
}

will be transform to

.someClass {
    background: url('../img/a.png');
}

But, y.css should be ../../img/a.png.

Can you change the setting of relative mode, because not all css entry files are in the first level directory.

Plugin cut DXImageTransform properties

Form valid property like this

filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#eeeeee', GradientType=0)

Plugin make invalid property

filter: progid:DXImageTransform

Manual inline

Automatic inline by file size is a bad way (it is come from early Grunt tools). For example, I connect font files and I know, that italic bold version is used very rare. So I should have some inline() function:

@font-face {
  font-family: "Franklin Gothic";
  font-weight: normal;
  font-style: normal;
  src: inline("franklin-gothic/regular.woff") format("woff");
}

@font-face {
  font-family: "Franklin Gothic";
  font-weight: bold;
  font-style: normal;
  src: inline("franklin-gothic/demi.woff") format("woff");
}

@font-face {
  font-family: "Franklin Gothic";
  font-weight: bold;
  font-style: italic;
  src: font-url("franklin-gothic/demi-italic.woff") format("woff");
}

In Rails Assets we no use Rails Sass Images for this tasks with inline function.

/cc @borodean

Wrong size of svg

If I have a svg with a viewbox (e.g "0 0 130 19") the result of size() ist not "130px 19px". It is "100px 100px", because of the attributes width="100%" height="100%".

Use PostCSS 4.1 API

PostCSS Plugin Guidelines are mandatory right now. Because all of rules are about ecosystem health.

Cachebusting with Grunt

I'm having issues using the cachebuster option. I know I have things set up correctly because I can use the other options (inlining, dimensions) successfully. Here are my settings:

var assets  = require('postcss-assets');

grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),
  postcss: {
    options: {
      processors: [
        assets({
          cachebuster: true
        })
      ]
    },
    dist: {
      src: 'build/src.css',
      dest: 'build/compiled.css',
    }
  }
});

And here's my CSS:

.image {
  background: url("../images/image.png");
}

Am I missing something here?

Error handling

  1. Why you print warning insetad of throw a error? Many build tools doesn’t show a warnings and it makes debug harder.
  2. PostCSS has special API to get source of node (even by previous source map):
if ( !isFound ) {
    throw decl.error('Asset not found or unreadable: ' + assetPath)
}

Windows problem: backslashes returned for css output

I'm on a Windows machine and using postcss-assets. When I use resolve() in combination with the 'relativeTo' option, I receive double backslashes as css output instead of a simple /

/* source input: */
.selector { background-image: resolve('filename.png'); }
/* generated output: */
.selector { background-image: url('..\\images\\filename.png'); }
/* expected output: */
.selector { background-image: url('../images/filename.png'); }

Can’t find repo

I’m having some issues when using an old version of postcss-assets (v2.1.3).

Started getting the following error on npm install:

npm ERR! Error: Command failed: Cloning into bare repository '/Users/ashley.nolan/.npm/_git-remotes/git-github-com-borodean-image-size-0541338d'...
npm ERR! remote: Repository not found.
npm ERR! fatal: repository 'https://github.com/borodean/image-size/' not found

Is this something that can be fixed? Looks like it’s looking for a fork that no longer exists? (we can’t upgrade to the latest version right now as we’re in process of upgrading our build servers to something that ressembles recent!)

Thanks

Get negative image width/height

How can I get image width or height with negative sign. For example I want to achieve this:

margin-left: -width('image.jpg');

But it is not rendered properly.

Output assets to distribution dir

So, I'm trying to figure out how to output the assets processed by postcss-assets to another directory, the dist directory.

I'm assuming this isn't the purpose of this plugin and that I'll need to pipe the output to another plugin possibly. I'm currently using the static-render-webpack-plugin webpack plugin which handles most of this including, through the file-loader, required assets.

Am I correct in assuming that postcss-assets doesn't work in this fashion, and assuming not, can you please point me in the correct direction on how to chain another plugin that can take the path generated from this plugin to output the files in a dist dir? Thanks.

Usage with postcss-at2x

Hi! I use postcss-assets. It's really cool, thank you.

Can I use it with postcss-at2x?

This way don't work:

background: inline('./img/image.png') at-2x;

ChangeLog

What is a changes in 2.0.0? I think every project must have ChangeLog.md so users willunderstand what is changed, when they see I new version on npm.

`inline` compiles all images to white

We replaced url('…') with inline('…') and noticed that all images suddenly had the same (white) base64 encoded string. My expectation was that they would work similarly on the same path.

Add dependency message

New postcss-loader will support dependency message to notify webpack about imports. So we need to add few lines on every import:

result.messages.push({
  type: 'dependecy',
  parent: currentFilePath,
  file: absoluteFilePath
})

@borodean it is not really necessary for images plugins. But I think it will be good to have it here too.

Mocha and Chai

Do you have any reason, why you love tape instead of mocha with chai?

mocha can get you:

  • Better output with colors and readable structure.
  • Better diffs.

I can send PR if you agree to mocha (because anyway it is a a matter of taste).

loadPaths should be able to handle glob

Hi @borodean, I think the loadPaths option does not handle glob patterns. It would be an useful feature i think.

assets({
  basePath: config.SRC_DIR,
  loadPaths: [path.join(config.DEST_DIR, '**/*')],
  relativeTo: 'public/css'
})
[21:54:48] Starting 'css'...

events.js:141
      throw er; // Unhandled 'error' event
      ^
Error: postcss-assets: /Users/tsm/Sites/__projects/gulp-starter/src/css/main.css:2:3: Asset not found or unreadable: sample.jpeg
Load paths:
  /Users/tsm/Sites/__projects/gulp-starter/src
  /Users/tsm/Sites/__projects/gulp-starter/public/**/*
.sample-bg-image {
  background-image: resolve("sample.jpeg"); }

Ability to delete assets after inlining.

This feature could be useful for builds where images are also optimized and copied into a bin folder. This way there wouldn't have to be a public facing copy of the image and the dist folder can be smaller.

TypeError in node 6.9.0

postcss-assets doesn't work with a simple gulp setup on 6.9.0:

return gulp.src( [__dirname + '/assets/sass/**/*.scss'] )
    .pipe(
      postcss([
        assets(),
        reporter({
          clearMessages: true,
          throwError: true
        })
      ],
      { syntax: syntax })
    )
    .pipe(
      sass({
        includePaths: __dirname + '/assets/sass',
        errLogToConsole: true
      })
    )
    .pipe(
      postcss([
        autoprefixer({ browsers: ['last 2 versions', 'ie > 10'] })
      ])
    )
    .pipe(gulp.dest(__dirname + '/public/assets/css'));

Errors out with assets()

events.js:160
      throw er; // Unhandled 'error' event
      ^
TypeError: Path must be a string. Received null
    at assertPath (path.js:7:11)
    at Object.resolve (path.js:1146:7)
    at /Users/mase/Code/be.net/node_modules/assets/lib/path.js:30:23
    at Array.map (native)
    at /Users/mase/Code/be.net/node_modules/assets/lib/path.js:29:29
    at tryCatcher (/Users/mase/Code/be.net/node_modules/assets/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/mase/Code/be.net/node_modules/assets/node_modules/bluebird/js/release/promise.js:510:31)
    at Promise._settlePromise (/Users/mase/Code/be.net/node_modules/assets/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (/Users/mase/Code/be.net/node_modules/assets/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Users/mase/Code/be.net/node_modules/assets/node_modules/bluebird/js/release/promise.js:691:18)
    at Promise._fulfill (/Users/mase/Code/be.net/node_modules/assets/node_modules/bluebird/js/release/promise.js:636:18)
    at /Users/mase/Code/be.net/node_modules/assets/node_modules/bluebird/js/release/nodeback.js:42:21
    at f (/Users/mase/Code/be.net/node_modules/once/once.js:25:25)
    at Glob.<anonymous> (/Users/mase/Code/be.net/node_modules/glob/glob.js:146:7)
    at emitOne (events.js:96:13)
    at Glob.emit (events.js:188:7)
    at Glob._finish (/Users/mase/Code/be.net/node_modules/glob/glob.js:185:8)
    at done (/Users/mase/Code/be.net/node_modules/glob/glob.js:172:12)
    at Glob._processSimple2 (/Users/mase/Code/be.net/node_modules/glob/glob.js:683:3)
    at /Users/mase/Code/be.net/node_modules/glob/glob.js:653:10
    at Glob._stat2 (/Users/mase/Code/be.net/node_modules/glob/glob.js:764:10)
    at lstatcb_ (/Users/mase/Code/be.net/node_modules/glob/glob.js:741:12)
    at RES (/Users/mase/Code/be.net/node_modules/inflight/inflight.js:31:16)
    at f (/Users/mase/Code/be.net/node_modules/once/once.js:25:25)
    at FSReqWrap.oncomplete (fs.js:123:15)

Are you able to glob loadPaths?

Sometimes we have multiple folders inside the img folder but they are different per project so i wouldn't be able to add them all the the loadPaths. If this is available or was added how does it deal with name conflicts?

Improve SVG encoding in data URIs

First of all, thank you for PostCSS Assets!

I think the encoding of SVGs in data URIs can be improved as described in the blog post Optimizing SVGs in data URIs. The method "Optimized URL-encoded" yields a smaller result than "Fully URL-encoded".

postcss-svgo uses the optimized URL-encoding. (But in my specific use case the SVG files have already been processed by SVGO when I pass them to PostCSS Assets. So ideally I do not want to run them through SVGO a second time.)

Sizes to background-size

How I can set image width and height to background-size? It is very important for HiDPI images.

For example, in Rails Sass Images we have image-width and image-height function. They accept file name at fisrt argument and zoom level as second.

So we can write:

.photo {
  background: inline('photo.2x.jpg');
  width: image-width('photo.2x.jpg', 2);
  height: image-height('photo.2x.jpg', 2);
  background-size: image-width('photo.2x.jpg', 2) image-height('photo.2x.jpg', 2);
}

/cc @borodean

Need clarification of multiple loadpath

If I want to use multiple LoadPaths

var options = {
  loadPaths: ['fonts/', 'media/patterns/', 'images/']
};

In gulp task, will it be like this?

return gulp.src('source/*.css')
    .pipe(postcss([assets({
      loadPaths: ['options']
    })]))

I couldn't install postcss-assets

Do:

npm install postcss-assets --save-dev

Result:

npm WARN addRemoteGit borodean/image-size resetting remote /Users/user/.npm/_git-remotes/git-github-com-borodean-image-size-git-12731099 because of error: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
npm ERR! git clone --template=/Users/user/.npm/_git-remotes/_templates --mirror git://github.com/borodean/image-size.git /Users/user/.npm/_git-remotes/git-github-com-borodean-image-size-git-12731099: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
npm WARN addRemoteGit borodean/image-size resetting remote /Users/user/.npm/_git-remotes/https-github-com-borodean-image-size-git-5f9ee4be because of error: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
npm ERR! git clone --template=/Users/user/.npm/_git-remotes/_templates --mirror https://github.com/borodean/image-size.git /Users/user/.npm/_git-remotes/https-github-com-borodean-image-size-git-5f9ee4be: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
npm WARN addRemoteGit borodean/image-size resetting remote /Users/user/.npm/_git-remotes/git-github-com-borodean-image-size-git-c4d823c8 because of error: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
npm ERR! git clone --template=/Users/user/.npm/_git-remotes/_templates --mirror [email protected]:borodean/image-size.git /Users/user/.npm/_git-remotes/git-github-com-borodean-image-size-git-c4d823c8: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "postcss-assets" "--save-dev"
npm ERR! node v4.1.1
npm ERR! npm  v2.14.4
npm ERR! code 1

npm ERR! Command failed: git clone --template=/Users/user/.npm/_git-remotes/_templates --mirror [email protected]:borodean/image-size.git /Users/user/.npm/_git-remotes/git-github-com-borodean-image-size-git-c4d823c8
npm ERR! xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
npm ERR! 
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Applications/MAMP/htdocs/gulp-test/npm-debug.log

What i am doing wrong?

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.