npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

less-src-replace

v1.6.5

Published

LESS plugin to copy all src files into one flatten structure.

Downloads

16

Readme

less-src-replace

Copy all local src files into one flatten structure and replaces paths relatively in final CSS file.

First of all, big thanks for less-plugin-inline-urls, which allows me to understand Visitor concept in LESS.

During complex development you will be having a lot of static files (fonts, images) expanded to different directories. For instance you may have:

  • bower directory
  • npm directory
  • local static files for different places in your app (ex. bundles in php symphony app)

Thanks to this plugin you will be able to keep expanded structure, but all of them are copied in flatten way for each LESS loaders.

Usage

Instalation

npm install --save-dev less-src-replace

API

less-src-replace ought to be called with Object with keys as follows:

dest

Type: String

Destination path where all static files should be copied into one directory.

{
    dest: __dirname + 'app/assets/static',
    ...
}

finalCSSPath

Type: String

Path of your final css needed to create relative src paths to all statics already copied.

{
    finalCSSPath: __dirname + 'app/assets/css',
    ...
}

This will cause that src paths in CSS would be looking like this: url: src('../static')

ignore

Type: Array optional

Array of paths that should be ignored during copy process.

{
    ignore: [__dirname + '/vendor']
    ...
}

This will cause that files in this directory won't be copied, path will keep relativity from final CSS.

Example Gulpfile

var getSrcFilesManager = require('less-src-replace');
    cssPath = __dirname + 'web/assets/css';

gulp.task('compileLESS', function(){
  gulp.src(['app/bundleName/stylesheets/loaderName.less'])
    .pipe(less({
        plugins: [new getSrcFilesManager({
            dest: __dirname + 'web/assets/static',
            finalCSSPath: cssPath,
            ignore: [__dirname + 'vendor']
        })]
    }))
    .pipe(gulp.dest(cssPath));
});

Nice to know

  • if your src url is remote address (starts with "//" or "~://"), obviously it won't be used
  • if your css has specific url used more than once, the file will be copied once as well
  • all of your copied static files have some random number as a prefix in file to prevent naming conflicts (and refresh cache in browser)

So your final public structure can look like (all of them are not in ignore paths):

.
├── css
│   └── loaderName.css
└── static
    ├── 17089248960837722-fontawesome-webfont.ttf
    ├── 19754130695946515-logo_google.png
    ├── 30828309641219676-fontawesome-webfont.woff
    ├── 33208357309922576-fontawesome-webfont.woff2
    ├── 6342896649148315-fontawesome-webfont.svg
    └── 9496213241945952-fontawesome-webfont.eot