Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including less-import with all npm packages installed. Try it out:

var lessImport = require("less-import")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

less-import v0.0.2

Browserify plugin to import less files from javascript source

less-import

Browserify plugin to import less files from javascript source

Install

npm install less-import --save-dev

GulpFile

To use less-import, you only need to activate the pluggin, passing a destination directory, and the gulp instance.

var lessImport = require('less-import');
var gulp = require('gulp');
var browserify = require('browserify');

var bundler = browserify('./src/javascript/app.js')
  // Activating less-import plugin
  .plugin(lessImport({
    dest: 'path/to/directory',
    gulp: gulp
  }))

// Building JS source
bundler.bundle().pipe(gulp.dest('./build/'));

Code

In your code, you can import .less files as normal, they will be parsed and saved in the directory specified.

mycomponent.js

// .. require JavaScript source

require('./mycomponent.less');

mycomponent.less

// .. import additional less files
@import 'sub-component.less'

.my-component {
  /* ... */
}

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free