Skip to content

Instantly share code, notes, and snippets.

@MiguelCastillo
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiguelCastillo/37944827c0caee3c0e1a to your computer and use it in GitHub Desktop.
Save MiguelCastillo/37944827c0caee3c0e1a to your computer and use it in GitHub Desktop.
Sample config for bit-imports
//https://github.com/MiguelCastillo/bit-loader
//https://github.com/MiguelCastillo/bit-imports
/* jshint -W098 */
var require = (function() {
/* jshint +W098 */
var importer = bitimports.config({
"baseUrl": "../",
"paths": {
"chai": "../node_modules/chai/chai",
"lessTransform": "test/js/lessTransform"
}
});
importer.ignore({
match: ["chai", "dist/bit-loader"]
});
importer.plugin("js", {
match: {
path: ["**/*.js"]
}
});
importer.plugin("css", {
match: {
path: ["**/*.css", "**/*.less"]
},
fetch : fetchStyle,
transform : cssTransform,
dependency : [cssContent],
compile : lessCompile
});
importer.plugin("less", {
match: {
path: ["**/*.less"]
},
transform : [{handler: "lessTransform", options: {"test": "that"}}, {handler: lessTransform, options: {"local": "options"}}],
dependency : [lessDependency],
compile : lessCompile
});
importer.plugin("json", {
match: {
path: ["**/*.json"]
},
compile : jsonCompile
});
function fetchStyle(moduleMeta) {
console.log("styleFecth", moduleMeta);
moduleMeta.source = "Initial source - ";
}
function lessTransform(moduleMeta, options) {
console.log("lessTransform local", moduleMeta, options);
moduleMeta.source += "some less [transform] ";
}
function lessDependency(moduleMeta) {
console.log("lessDependency", moduleMeta);
moduleMeta.source += "some less [dependency] ";
}
function lessCompile(moduleMeta) {
console.log("lessCompile", moduleMeta);
moduleMeta.code = "compiled less file";
}
function cssTransform(moduleMeta) {
console.log("cssTransform", moduleMeta);
moduleMeta.source += "some css [transform] ";
}
function cssContent(moduleMeta) {
console.log("cssContent", moduleMeta);
moduleMeta.source += "some css [dependency] ";
}
function jsonCompile(moduleMeta) {
console.log("jsonCompile", moduleMeta);
moduleMeta.code = JSON.parse(moduleMeta.source);
}
bitimports.Logger.enableAll();
return importer.require;
}());
require('!test/style/test.css', function(content) {
console.log(content);
});
require("!test/style/test.less", function(content) {
console.log(content);
});
require(["!package.json", "!test/json/array.json", "!test/json/artists.json"], function(modules) {
console.log(modules[0], modules[1], modules[2]);
});
@MiguelCastillo
Copy link
Author

The require method is exposed that way for illustration purposes. Bitimports instance is a full system loader with an interface compatible with ES6 module loader. E.g. System.import. Exposing the require call that way is also how we can get babel transforms working directly in the browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment