# grunt-less-imports

> A grunt task to create LessCSS @import statements from a collection of stylesheet files

Latest version **1.2.2** (published 2016-02-25) · 0 weekly downloads

## Install

```sh
npm install grunt-less-imports
pnpm add grunt-less-imports
yarn add grunt-less-imports
bun add grunt-less-imports
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2016-02-25 |
| First published | 2013-04-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Marc Diethelm |
| Maintainers | marcdiethelm |
| Keywords | gruntplugin, less, lessCSS, import, @import, debug, error messages |

## Links

- npm: https://www.npmjs.com/package/grunt-less-imports
- Repository: https://github.com/MarcDiethelm/grunt-less-imports
- Issues: https://github.com/MarcDiethelm/grunt-less-imports/issues
- npm.io page: https://npm.io/package/grunt-less-imports

## Dependencies (1)

- [slash](https://npm.io/package/slash.md) ^1.0.0

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.2.2 (latest) — 2016-02-25
- 1.2.1 — 2016-02-23
- 1.2.0 — 2016-02-23
- 1.1.0 — 2014-11-06
- 1.0.0 — 2014-09-27
- 0.9.1 — 2014-01-19
- 0.9.0 — 2014-01-18
- 0.8.7 — 2013-08-23
- 0.8.6 — 2013-05-30
- 0.8.5 — 2013-05-20
- 0.8.4 — 2013-04-29

## README

[![Build status](https://img.shields.io/travis/MarcDiethelm/grunt-less-imports.svg)](https://travis-ci.org/MarcDiethelm/grunt-less-imports) &nbsp; ![npm version](https://img.shields.io/npm/v/grunt-less-imports.svg) &nbsp; ![npm version](https://img.shields.io/badge/license-MIT-blue.svg) &nbsp; ![37KB installed size](https://img.shields.io/badge/installed%20size-37KB-brightgreen.svg)

---

# grunt-less-imports

A grunt task to create LessCSS @import statements from a collection of stylesheet files.

```less
@import (once) "filename"; // <-- these. in a file. automatically.
```

Why use this? To get useful error messages from the LessCSS parser, that tell you in what file the error was encountered!
LessCSS uses @import statements to aggregate files and will tell you about parsing errors in those files.
But maintaining these statements by hand is a pain. In order to automatically aggregate all the style files in a project,
a method of first concatenating the files before parsing is widely used. This works but you loose the valuable
information about where to fix your mistakes.

So, automate @import creation with this plugin and use the resulting file as the source for the LessCSS parser.

By default any .css source files are inlined in the generated file before the @import statements.

## Getting Started
This plugin requires Grunt `^0.4.5`.

Alternatively [grunty](https://github.com/bahmutov/grunty) allows to any grunt plugin as NPM script without Gruntfile.js

If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the
[Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a
[Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with
that process, you may install this plugin with this command:

```shell
npm install grunt-less-imports --save-dev
```

`--save-dev` adds the plugin to your devDependencies.

Once the plugin has been installed, load it in your `Gruntfile.js` like so:

```js
grunt.loadNpmTasks('grunt-less-imports');
```

## The "less_imports" task

### Overview
In your project's Gruntfile, add a section named `less_imports` to the data object passed into `grunt.initConfig()`.

```js
grunt.initConfig({
	less_imports: {
		options: {
			// Task-specific options go here.
		},
		your_target: {
			// Target-specific file lists and/or options go here.
		}
	}
})
```

### Options

- **options.inlineCSS** `{Boolean} true`  
By default any `.css` source files are inlined in the output before the `@import` statements for the less files start.
  LessCSS itself will generate CSS from `.less` @import statements, but any `.css` @imports are left as is. If that's the behavior
  you want, set `inlineCSS` to false. The @imports will be created in order of the provided files.

- **options.banner** `{String} "// This file was generated by grunt-less-imports"`  
This option contains the banner that is added to the beginning of the generated output file.

- **options.import** `{String|Function} "once"`  
Set Less [import option keyword](http://lesscss.org/features/#import-options).  
  String: Set the keyword for all `@import` statements in the task target.  
  Function: Dynamically set the `@import` keyword with a callback. The path and extension of the current file are passed as arguments. The function must return a string.


#### Examples
Basic example with options

```js
grunt.initConfig({
	less_imports: {
		options: {
			inlineCSS: false, // default: true
			import: 'reference' // default: once
		},
		src: [ 'styles/*.css', 'styles/*.less'],
		dest: 'temp/imports.less'
	}
})
```

---

### More Examples

#### Using 'files' shorthand notation
In this example, a `files` shorthand is used to specify input files and the output file instead of `src` and `dest`.

```js
grunt.initConfig({
	less_imports: {
		options: {
		},
		files: {
			'dist/imports.less': ['styles/styles.css', 'styles/styles.less']
		}
	}
})
```

#### Using multiple task targets

```js
grunt.initConfig({
	less_imports: {
		options: { // general task options
			inlineCSS: false
		},
		project: {
			src: [ 'styles/*.css', 'styles/*.less'],
			dest: 'dist/project.less'
		},
		vendor: {
			options: { // target-specific options
				import: 'reference'
			},
			src: [ 'styles/vendor/*.css', 'styles/vendor/*.less'],
			dest: 'dist/vendor.less'
		}
	}
})
```

#### Example with a options.import callback

```js
grunt.initConfig({
	less_imports: {
		options: {
			import: function(filepath, extension) {
				if (filepath === 'styles/helpers.less')
					return 'reference';
				else
					return 'once';
			}
		},
		src: [ 'styles/*.css', 'styles/*.less'],
		dest: 'temp/imports.less'
	}
})
```

## Troubleshooting

Run the task with the debug and verbose options. This will give you a lot of info about what's going on.

```bash
grunt less_imports --debug --verbose
```

To just run a specific task target

```bash
grunt less_imports:target-name --debug --verbose
```

Debug will make grunt-less-imports print out more info, and verbose is used by grunt to be, well, really quite verbose.

## Contributing

- Clone the project from https://github.com/MarcDiethelm/grunt-less-imports.git
- `npm install` (no global dependencies required)
- `npm test`

[How to contribute to a project on Github](https://github.com/MarcDiethelm/contributing/blob/master/README.md)

## Release History
see [CHANGELOG.md](CHANGELOG.md)

---
_Source: https://npm.io/package/grunt-less-imports · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
