This Plugin lets your create a LESS import file automatically by running threw specified folders. This is useful if you are at the beginning of the development-process and want easily change the structure or names of your files and folders without having to care for the import statements in your "master" less file.
This plugin requires Grunt ~0.4.1
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-lessimportfile --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-lessimportfile');
In your project's Gruntfile, add a section named importfile
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
lessimportfile: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
asReferenceIdentifier
Type: String
Default value: "__"
Import the prefixed file as a reference. It will create an import-statement like this:
@import (reference) "__file.less"
Type: Boolean
Default value: false
Import the specified files as a reference. It will create an import-statement like this:
@import (reference) "file.less"
Type: Boolean
Default value: false
Keep the content of the specified target file.
Type: String
Default value: "oc__"
Type: Boolean
Default value: true
Type: Array
Default value: []
In this example, the default options are used.
grunt.initConfig({
lessimportfile: {
options: {},
files: {
'your-framework/master.less': ['your-framework/modules/**/*.less', 'your-framework/variables.less']
},
},
})
In this example, custom options are used.
grunt.initConfig({
lessimportfile: {
setup: {
options: {
asReferenceIdentifier: '_r_'
},
files: {
'your-framework/master.less': ['your-framework/base/**/*.less']
},
},
framework: {
options: {
asReference: true,
copyExisting: true
},
files: {
'your-framework/master.less': ['your-framework/abstract-modules/**/*.less'],
},
},
components: {
options: {
copyExisting: true,
includeAllComponents: false,
optionalComponentIdentifier: 'comp__',
optionalComponentsList: ['comp__flyout-nav.less', 'comp__accordion.less']
},
files: {
'your-framework/master.less': ['your-framework/components/**/*.less']
},
},
ui: {
options: {
copyExisting: true
},
files: {
'your-framework/master.less': ['your-framework/ui/**/*.less', 'your-framework/variables.less']
},
},
},
})
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
- Initial Release
- Added some options to mark specific files (components) as optional
- Added an option to import files as reference via a custom file prefix