本文整理匯總了TypeScript中resolve-from.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: loadDojoLoader
export default function loadDojoLoader ({ peerDependencies = {} }: any) {
const baseUrl = process.cwd();
const packages = [
{ name: 'src', location: '_build/src' }
];
for (const name in peerDependencies) {
if (/^dojo-/.test(name)) {
packages.push({ name, location: join('node_modules', name, 'dist', 'umd') });
}
else if (name === '@reactivex/rxjs') {
packages.push({ name: 'rxjs', location: join('node_modules', name, 'dist', 'amd') });
}
else if (name === 'maquette' || name === 'immutable') {
packages.push({ name, location: join('node_modules', name, 'dist') });
}
else {
packages.push({ name, location: join('node_modules', name) });
}
}
// Assume dojo-loader is installed in the parent project.
const r = require(resolveFrom(baseUrl, 'dojo-loader'));
r.config({
baseUrl,
packages
});
return {
baseUrl,
packages,
require: r
};
}
示例2: require
grunt.registerTask('repl', 'Bootstrap dojo-loader and start a Node.js REPL', function () {
this.async(); // Ensure Grunt doesn't exit the process.
const { baseUrl, packages, require: dojoRequire } = loadDojoLoader(packageJson);
const nodeRequire = function (mid: string) {
// Require relative to the baseUrl, not this module.
return require(resolveFrom(baseUrl, mid));
};
Object.defineProperty(nodeRequire, 'resolve', {
configurable: false,
enumerable: true,
value (mid: string) {
return resolveFrom(baseUrl, mid);
}
});
grunt.log.ok(`Available packages: ${packages.map(({ name }) => name).join(', ')}`);
grunt.log.ok('require() is now powered by dojo-loader');
grunt.log.ok('Node.js\' require() is available under nodeRequire()');
const { context } = repl.start();
Object.defineProperties(context, {
nodeRequire: {
configurable: false,
enumerable: true,
value: nodeRequire
},
require: {
configurable: false,
enumerable: true,
value: dojoRequire
}
});
});