Git Product home page Git Product logo

less-plugin-glob's Introduction

less-plugin-glob

Globbing support in Less-imports.

Travis status npm version David

This plugin allows to import multiple files using glob expressions. Add this plugin and you can write import like this

@import "common/**";
@import "themes/**";

How to add plugins?

Section about plugins in Less documentation

Examples

lessc usage

  1. npm install -g less less-plugin-glob
  2. Create file with import by glob, something like @import "includes/**"
  3. Run lessc --glob styles.less styles.css and enjoy whole your styles concated by one line

Programmatic usage

  1. Install plugin locally npm install less-plugin-glob
  2. Import it and add into plugins section of options.
less.render(lessString, { plugins: [require('less-plugin-glob')] })

If you are using Gulp or Grunt or something else, you can import and add plugin by same way as well.

Usage with webpack and less-loader

When using webpack and less-loader >= 4.0, it's important to make sure that less-loader is configured not to use its webpack resolver, which is now active by default. Otherwise, less-plugin-glob won't run at all because less-loader applies a LESS plugin that passes all queries to the webpack resolver (bypassing this plugin). To make less-loader revert to the LESS resolver, specify the paths loader option:

{
  loader: "less-loader",
  options: {
    plugins: [lessPluginGlob],
    paths: [path.resolve(__dirname, "path/to/my/styles")] // This is the important part!
  }
}

less-plugin-glob's People

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

less-plugin-glob's Issues

Usage in webpack?

Hello.
Love the plugin concept.
Any chance this works in webpack? If yes how?

Unable to make it work

I installed your plugin and added it in my webpack options like this:

'lessLoader': {
'lessPlugins': [
require('less-plugin-glob')
]
}

now in my main.less file I am using it like this:
@import "./../../styles/less/**";

I keep getting an error

ERROR in .//css-loader!.//less-loader?root=true!./src/assets/styles/less/rsm.less
Module build failed: Cannot resolve 'file' or 'directory' ./C:(path)\less\rsm.less in ./../../styles/less
@ ./../../styles/less/**.less (line 3, column 0)
near lines:
@import "C:(path)\less
\rsm-style.less";
@import "C:(path)\less
\rsm.less";

@ ./src/assets/styles/less/rsm.less

am I missing something?
Thanks

Installing with Grunt

I'm having some issues getting this to work with Grunt, can you please take a look:

This is the less section of my Gruntfile.js:

            less: {
                development: {
                    options: {
                        paths: ['<%= directory %>assets_new/css'],
                        plugins: [require('less-plugin-glob')]
                    },
                    files: {
                        '<%= directory %>assets_new/css/style.css': '<%= directory %>assets_new/css/src/__bootstrap.less'
                    }
                }
            },

My less file contains:
@import "breakpoint_desktop/**";

When I build, I'm getting the following error:

FileError: 'breakpoint_desktop/.less' wasn't found in...
@import "breakpoint_desktop/
";

Thanks.

Add configuration option to change the way file paths are generated

When building with webpack, all file paths should be relative to webpack project root, otherwise files will not be resolved.

The error message from webpack:

ERROR in .//css-loader!.//less-loader!./src/styles/styles.less
Module build failed: Cannot resolve 'file' or 'directory' ./C:\dev-x\angular2-ts-boilerplate\src\app\app.component.less in ../app
@ ../app/**.less (line 1, column 0)
near lines:

@import "C:\dev-x\angular2-ts-boilerplate\src\app\app.component.less";

@ ./src/styles/styles.less 4:14-123

Globbing Not Functioning

I can't get your plugin to work... I assume I'm doing something wrong.

Has anyone else gotten it to work?

Not getting any errors... just no output when I try to use globbing.

gulp.task( 'styles', () => {
  return gulp.src( [ 'app/styles/main.less' ] )
    .pipe( $.less( {
      plugins: [ require( 'less-plugin-glob' ) ],
    } ) )
    .pipe( gulp.dest( 'dist/styles' ) );
} );
// main.less
// Each line below is tried on it's own of course.
@import "app/module/waffle.less"; // Works
@import "app/module/**"; // Does not work.
@import "app/module/**/*"; // Does not work.
@import "app/module/**/*.less"; // Does not work.

Upgrading from 1.0.0 to 1.0.1 caused an issue

caused less to import weird things and resulted in this:

>> SyntaxError: Invalid HEX color code in node_modules/grunt-contrib-less/node_modules/less/test/less/errors/color-invalid-hex-code2.less on line 2, column 29:
>> 1 .a {
>> 2     @wrongHEXColorCode: #fffblack;
>> 3 }
Warning: Error compiling src/less/frontend.less 

used as follows:

    less:
      src:
        options:
          paths: [
            "src/less",
            "node_modules/bootstrap/less",
            "node_modules/slick-carousel/slick",
            "node_modules/animate.css"
          ]
          plugins: [require("less-plugin-glob")]

Globbing Pattern seems wrong

so when I am trying to import a collection of less files into a sort of main less file, the globbing pattern does not work as it normally does.

star is my key for asterix *
starstar is two **

You would expect this to work:
@import "starstar/shared";
@import "starstar/phone";
@import "**/tablet";

The above would then go through all directories and sub-directories to find the files that match shared, phone and tablet. however, it does not.

When i use single stars (see below) it goes into the next directory and no further. Therefore i can't reach any further than one directory so reaching something like main/example/target.less would not work. However, main/target.less would.
@import "star/shared";
@import "star/phone";
@import "star/tablet";

Overall there seems to be an issue with using ** to go through multiple directories and I'm not quite sure.

I've tried ./**/shared; to ensure the directory base is correct and no avail.

Advanced glob patterns not working

I am looking for a way to include all less files in a structure but explicitly exclude some.

According to node-glob

Something like this should work:
@import "['header/*.less', '!header/terms.less']";

It seems to me that none of these advanced patterns are working. e.g.:
[...]
!(pattern|pattern|pattern)

Please specify which glob patterns are actually working

make compatible with grunt-contrib-less

just-boris i use grunt-contrib-less they have a example how to load plugin's like this:

plugins: [
new (require('less-plugin-autoprefix'))({browsers: ["last 2 versions"]}),
new (require('less-plugin-clean-css'))(cleanCssOptions)
],

How would i load your wonderfull plugin in here so that it works with grunt-contrib-less?

Request custom `processPaths()` callback

feature request

Thank you for creating this awesome plugin!

I was wondering if I could ask for a feature to be added to it.

Could you please add a method to pass a custom processPaths() filter to the plugin?

I was thinking something such as lessPluginGlob.options({filter: myFunc})) in order to pass a function.

reasoning

I need to customize the filter in my gulp workflow for the following reasons:

  1. Using fancy-log instead of console.warn to match the rest of output
  2. Either ignoring the "Here is non-less file:" warnings for some extensions (e.g. *.disabled), or displaying custom messages (e.g. File skipped: <name>.disabled 1
  3. Process custom extensions (e.g. *.global-less and *.local-less) as css/less files
  4. Using chalk in Node

1 The reason for this is that I sometimes rename my filename.less to filename.less.disabled in order to exclude it from the glob, without needing to write an exclusion rule.

Here's an example function that I would want to pass:

function processPaths(paths) {
    return paths.filter(function(filepath) {
        var ext = path.extname(filepath);
        if( ['less', 'css', 'custom'].indexOf(ext.replace(/^\./, '')) > -1 )
            return true;
        if ( ext === '.disabled' )
            logger.warn(chalk`{yellow Less file skipped:} ${filepath}`);
        else console.warn(chalk`{yellow Here is non-less file:} ${filepath}, {red ignored}`);
        return false;
    });
}

n.b.

I believe this would be a safe (i.e. non-breaking) change.

Unable to load plugin

I'm getting this error after installing the plugin:

Unable to load plugin glob please make sure that it is installed under or at the same level as less

tried removing and reinstalling with no luck.

I can see the plugin under /usr/lib/node_modules/less-plugin-glob/

Working on ubuntu 16.04 with lessc 3.0.1

Import order is not deterministic

I found an issue where if I import a whole directory, for example @import "./objects/**/*";, the resulting output is not always sorted alphabetically. So, when - inside the directory - I have for example files named A.less, B.less, C.less, I would expect the order to be the same in the CSS output, yet it seems the plugin sometimes puts B.less first.

Add an NPM publish automation via Travis

This one will be really useful for you, as it allows you to publish your module on the npm registry by simply tagging your git codebase.

http://docs.travis-ci.com/user/deployment/npm/

Can't do a PR for that since it requires your email and api_key for npmjs.com (don't worry, it encrypts it)

After the initial setup, you can publish your module by doing so: git tag -a vVERSION_NUMBER -m "a commit message for the tag", i.e. git tag -a v1.1.0 -m "Release v1.1.0"

This way you will catch two birds with one stone (having tagged version of your module on github, and an automatic publish on npmjs).

Cheers.

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.