Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-twist-url-assets

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-twist-url-assets

Copies relatively accessed image resources to a specified folder and updates the output css to reflect the copied image paths.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

twistUrlAssets

Build this documentation with "npm run doc" This is a small postcss plugin that will transform relative url paths. My use case: Some npm packages use relative urls in their css. This is fine and dandy until you mash all your css together into one big file in some src directory and those relative urls no longer point to where they're supposed to. To fix this we can copy the image resources to a "dump" directory and change all the urls to be consistent and correct. Yay.

Travis CI Badge

Parameters

  • newUrlPathPrefix string The prefix that will be prepended to the generated image file. This will determine the path that the server uses to query for the image resource. eg "/static/images/dumped_assets"
  • dumpDirectoryPath string The place that you want to dump your image resorces. eg "/opt/path/to/static/images/dumped_assets"

Examples

Example usage of twistUrlAssets().

// Given: (style.css)
// .one {
//   background-image: url("images/center_icon.png");
// }
// .two {
//   background-image: url("cog.png");
// }
// .three {
//   background-image: url(data:image/gif;base64,R0lGODlh...IQA7);
// }
// .four {
//   background-image: url("/ignored_asset.png");
// }
// .five {
//   background-image: url("../example.svg");
// }

// Ouput:
// .one {
//    background-image: url("/static/images/style_dumped_center_icon.png");
//  }
//  .two {
//    background-image: url("/static/images/style_dumped_cog.png");
//  }
//  .three {
//    background-image: url(data:image/gif;base64,R0lGODlh...IQA7);
//  }
//  .four {
//    background-image: url("/ignored_asset.png");
//  }
//  .five {
//    background-image: url("/static/images/style_dumped_example.svg");
//  }

// Gulp
var gulp = require('gulp');
var postcss = require('gulp-postcss');

var twistUrlAssets = require('postcss-twist-url-assets');

gulp.task('css', function () {
  var processors = [
    twistUrlAssets('/static/images', '/opt/demo_gulp_twist_postcss/dest/static/images')
  ];
  return gulp.src('./src/*.css')
    .pipe(postcss(processors))
    .pipe(gulp.dest('./dest'));
});

// rollup-plugin-sass
var postcss = require('postcss');
var twistUrlAssets = require('postcss-twist-url-assets');
...
sass({
  ...
  processor(code, id) {
    return postcss([twistUrlAssets('/static/images', '/opt/demo_rollup_twist_postcss/dest/static/images')])
      .process(code, {from: id})
      .then((result) => {
        return result.css;
      });
  },
  ...
})

FAQs

Package last updated on 03 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc