You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
774 B

var path = require( 'path' );
var fs = require( 'fs' );
var assert = require( 'assert' );
var cachedModules = {
'@main.js': 'import foo from "./foo"; export default foo();'
};
module.exports = {
description: 'applies custom resolver to entry point',
options: {
plugins: [{
resolveId: function ( importee, importer ) {
if ( importer === undefined ) {
return '@' + path.relative( __dirname, importee );
}
if ( importer[0] === '@' ) {
return path.resolve( __dirname, importee ) + '.js';
}
},
load: function ( moduleId ) {
if ( moduleId[0] === '@' ) {
return cachedModules[ moduleId ];
}
return fs.readFileSync( moduleId, 'utf-8' );
}
}]
},
exports: function ( exports ) {
assert.equal( exports, 42 );
}
};