gulp-conkitty
Compile Conkitty Templates
Install
npm install gulp-conkitty --save-dev
Example
var conkitty = ; gulp;
here is actual example) and source map
Example with dependencies (var conkitty = ;var gulpFilter = ;var concat = ; gulp;
Life outside current working directory
In order to prevent destructivity, every file created by gulp-conkitty
should point somewhere inside current working directory:
// is ok // but // will throw an exception.
It is possible to rebase dependencies from outside your working directory.
Let's say we have project structure like this:
/root
/lib
button.css
.btn {background: red;}
button.ctpl
button $title
&"button.css"
button.btn[type="button"]
$title
/myproj
page.ctpl
page
CALL button "Hello world"
gulpfile.js
...
gulp.task('conkitty', function() {
return gulp.src(['./page.ctpl', '../lib/button.ctpl'])
.pipe(conkitty({
templates: 'tpl.js',
deps: true
}))
.pipe(gulp.dest('./build'));
});
...
package.json
And we run gulp
from /root/myproj
directory:
[gulp] Error in plugin 'gulp-conkitty': File `../lib/button.css` is outside current working directory
To fix that, we need to rebase outside dependencies and instead of deps: true
in gulpfile.js
add rebase map:
After that, gulp
will run conkitty
task fine and /root/myproj/build
directory will look like:
/build
/outerlib
button.css
tpl.js
You can rebase multiple directories from outside your working directory and use relative and absolute paths.
External libraries of templates
There is a bit of syntax sugar to add external libraries of templates.
.pipe(conkitty({
templates: 'tpl.js',
deps: true, // sould be enabled.
libs: {
// We could have npm package with library of templates.
superlib: require('mysuperlib')
}
}))
In this example require('mysuperlib')
should return an object with two
properties:
require('mysuperlib').BASE
should be an absolute path to library's base directoryrequire('mysuperlib').FILES
should be an array of paths to template files.
mysuperlib
file structure could look like:
/mysuperlib
package.json
mysuperlib1.ctpl
mysuperlib2.ctpl
index.js
module.exports = {
BASE: __dirname, // Actual path to index.js.
FILES: ['mysuperlib1.ctpl', 'mysuperlib2.ctpl']
};
Dependencies of external library (if any) will be rebased using libs
object
key:
.pipe(conkitty({
templates: 'tpl.js',
deps: true,
libs: {
superlib: require('mysuperlib'), // Dependencies will go to `superlib/*`
'complex/path/lib': require('mysuperlib2') // Dependencies will go to `complex/path/lib/*`
}
}))
Exclude concat.js from common file
By default concat.js is built in common file. You can exclude concat.js from common file:
gulp;
Passing environment object for precompile expressions
You can pass environment object for precompile expressions:
gulp;