UNPKG

lasso-require

Version:

Lasso.js plugin to support Node.js style module require in the browser

49 lines (39 loc) 1.22 kB
var transport = require('lasso-modules-client/transport'); var nodePath = require('path'); exports.create = function(config, lasso) { return { properties: { 'from': 'string', 'to': 'string', 'fromFile': 'string' }, init(lassoContext) { }, getDir: function() { return this.fromFile ? nodePath.dirname(this.fromFile) : undefined; }, read: function(context) { return transport.codeGenerators.remap( this.from, this.to, { modulesRuntimeGlobal: config.modulesRuntimeGlobal }); }, getLastModified: function(lassoContext, callback) { callback(null, -1); }, getSourceFile: function() { return this._sourceFile; }, calculateKey: function() { return 'modules-remap:' + this.from + '|' + this.to; }, getUnbundledTargetPrefix: function(lassoContext) { return config.unbundledTargetPrefix; }, getUnbundledTarget: function() { return 'lasso-modules-meta'; } }; };