本文整理汇总了TypeScript中rollup-pluginutils.createFilter函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createFilter函数的具体用法?TypeScript createFilter怎么用?TypeScript createFilter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createFilter函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: createVueFilter
export function createVueFilter(
include: Array<string|RegExp> | string | RegExp = [/\.vue$/i],
exclude: Array<string|RegExp> | string | RegExp = []
): (file: string) => boolean {
const filter = createFilter(include, exclude)
return id => filter(id)
}
开发者ID:liekkas,项目名称:rollup-plugin-vue,代码行数:8,代码来源:utils.ts
示例2: ionicRollupResolverPlugin
export function ionicRollupResolverPlugin(context: BuildContext) {
const filter = pluginutils.createFilter(INCLUDE, EXCLUDE);
return {
name: PLUGIN_NAME,
transform(sourceText: string, sourcePath: string): any {
if (!filter(sourcePath)) {
return null;
}
const jsSourcePath = changeExtension(sourcePath, '.js');
const mapPath = jsSourcePath + '.map';
if (context.fileCache) {
let file = context.fileCache.get(jsSourcePath);
let map = context.fileCache.get(mapPath);
// if the file and map aren't in memory, load them and cache them for future use
try {
if (!file) {
const content = readFileSync(jsSourcePath).toString();
file = { path: jsSourcePath, content: content};
context.fileCache.set(jsSourcePath, file);
}
} catch (ex) {
Logger.debug(`transform: Failed to load ${jsSourcePath} from disk`);
}
try {
if (!map) {
const content = readFileSync(mapPath).toString();
map = { path: mapPath, content: content};
context.fileCache.set(mapPath, map);
}
} catch (ex) {
Logger.debug(`transform: Failed to load source map ${mapPath} from disk`);
// just return null and fallback to the default behavior
return null;
}
if (!file || !file.content) {
Logger.debug(`transform: unable to find ${jsSourcePath}`);
return null;
}
let mapContent: string = null;
if (map && map.content) {
try {
mapContent = JSON.parse(map.content);
} catch (ex) {
}
}
return {
code: file.content,
map: mapContent
};
}
return null;
},
resolveId(importee: string, importer: string): any {
return resolveId(importee, importer, context);
},
load(sourcePath: string) {
if (context.fileCache) {
const file = context.fileCache.get(sourcePath);
if (file && file.content) {
return file.content;
}
}
return null;
}
};
}
开发者ID:Kode-Kitchen,项目名称:ionic-app-scripts,代码行数:81,代码来源:ionic-rollup-resolver-plugin.ts
示例3: typescript
export default function typescript ( options: Options ) {
options = assign( {}, options || {} );
const filter = createFilter(
options.include || [ '*.ts+(|x)', '**/*.ts+(|x)' ],
options.exclude || [ '*.d.ts', '**/*.d.ts' ] );
delete options.include;
delete options.exclude;
// Allow users to override the TypeScript version used for transpilation.
const typescript: typeof ts = options.typescript || ts;
delete options.typescript;
// Load options from `tsconfig.json` unless explicitly asked not to.
const tsconfig = options.tsconfig === false ? {} :
compilerOptionsFromTsConfig( typescript );
delete options.tsconfig;
// Since the CompilerOptions aren't designed for the Rollup
// use case, we'll adjust them for use with Rollup.
adjustCompilerOptions( typescript, tsconfig );
adjustCompilerOptions( typescript, options );
// Merge all options.
options = assign( tsconfig, getDefaultOptions(), options );
// Verify that we're targeting ES2015 modules.
if ( options.module !== 'es2015' && options.module !== 'es6' ) {
throw new Error( `rollup-plugin-typescript: The module kind should be 'es2015', found: '${ options.module }'` );
}
const parsed = typescript.convertCompilerOptionsFromJson( options, process.cwd() );
if ( parsed.errors.length ) {
parsed.errors.forEach( error => console.error( `rollup-plugin-typescript: ${ error.messageText }` ) );
throw new Error( `rollup-plugin-typescript: Couldn't process compiler options` );
}
const compilerOptions = parsed.options;
return {
resolveId ( importee: string, importer: string ): string {
// Handle the special `typescript-helpers` import itself.
if ( importee === 'typescript-helpers' ) {
return path.resolve( __dirname, '../src/typescript-helpers.js' );
}
if ( !importer ) return null;
if (path.sep !== "/") {
importer = importer.split(path.sep).join("/");
}
var result: ts.ResolvedModuleWithFailedLookupLocations;
if ( compareVersions( typescript.version, '1.8.0' ) < 0 ) {
// Suppress TypeScript warnings for function call.
result = (typescript as any).nodeModuleNameResolver( importee, importer, resolveHost );
} else {
result = typescript.nodeModuleNameResolver( importee, importer, compilerOptions, resolveHost );
}
if ( result.resolvedModule && result.resolvedModule.resolvedFileName ) {
if ( endsWith( result.resolvedModule.resolvedFileName, '.d.ts' ) ) {
return null;
}
return result.resolvedModule.resolvedFileName;
}
return null;
},
transform ( code: string, id: string ): { code: string, map: any } {
if ( !filter( id ) ) return null;
const transformed = typescript.transpileModule( fixExportClass( code, id ), {
fileName: id,
reportDiagnostics: true,
compilerOptions
});
const diagnostics = transformed.diagnostics ?
transformed.diagnostics.filter( goodErrors ) : [];
let fatalError = false;
diagnostics.forEach( diagnostic => {
var message = typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
if ( diagnostic.file ) {
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition( diagnostic.start );
console.error( `${diagnostic.file.fileName}(${line + 1},${character + 1}): error TS${diagnostic.code}: ${message}` );
} else {
console.error( `Error: ${message}` );
//.........这里部分代码省略.........
开发者ID:GiedriusGrabauskas,项目名称:rollup-plugin-typescript,代码行数:101,代码来源:index.ts
示例4: bundleJson
export default function bundleJson(config: d.Config, options: Options = {}) {
const path = config.sys.path;
const filter = createFilter(options.include, options.exclude);
const collectionDirs = (config.outputTargets as d.OutputTargetDist[]).filter(o => o.collectionDir).map(o => o.collectionDir);
return {
name: 'json',
resolveId(importee: string, importer: string): any {
if (importer && importee.endsWith('.json')) {
const collectionDir = collectionDirs.find(cd => importer.startsWith(cd));
if (collectionDir) {
return path.resolve(
path.dirname(importer).replace(collectionDir, config.srcDir),
importee
);
}
}
return null;
},
transform(json: string, id: string) {
if (id.slice(-5) !== '.json') return null;
if (!filter(id)) return null;
const data = JSON.parse(json);
let code = '';
const ast: ASTNode = {
type: 'Program',
sourceType: 'module',
start: 0,
end: null,
body: []
};
if (Object.prototype.toString.call(data) !== '[object Object]') {
code = `export default ${json};`;
ast.body.push({
type: 'ExportDefaultDeclaration',
start: 0,
end: code.length,
declaration: {
type: 'Literal',
start: 15,
end: code.length - 1,
value: null,
raw: 'null'
}
});
} else {
const indent = 'indent' in options ? options.indent : '\t';
const validKeys: string[] = [];
const invalidKeys: string[] = [];
Object.keys(data).forEach(key => {
if (key === makeLegalIdentifier(key)) {
validKeys.push(key);
} else {
invalidKeys.push(key);
}
});
let char = 0;
validKeys.forEach(key => {
const declarationType = options.preferConst ? 'const' : 'var';
const declaration = `export ${declarationType} ${key} = ${JSON.stringify(data[key])};`;
const start = char;
const end = start + declaration.length;
// generate fake AST node while we're here
ast.body.push({
type: 'ExportNamedDeclaration',
start: char,
end: char + declaration.length,
declaration: {
type: 'VariableDeclaration',
start: start + 7, // 'export '.length
end,
declarations: [
{
type: 'VariableDeclarator',
start: start + 7 + declarationType.length + 1, // `export ${declarationType} `.length
end: end - 1,
id: {
type: 'Identifier',
start: start + 7 + declarationType.length + 1, // `export ${declarationType} `.length
end: start + 7 + declarationType.length + 1 + key.length, // `export ${declarationType} ${key}`.length
name: key
},
init: {
type: 'Literal',
start: start +
//.........这里部分代码省略.........
开发者ID:franktopel,项目名称:stencil,代码行数:101,代码来源:json.ts
示例5: typescript
export default function typescript ( options ) {
options = assign( {}, options || {} );
const filter = createFilter(
options.include || [ '*.ts+(|x)', '**/*.ts+(|x)' ],
options.exclude || [ '*.d.ts', '**/*.d.ts' ] );
delete options.include;
delete options.exclude;
// Allow users to override the TypeScript version used for transpilation.
const typescript: typeof ts = options.typescript || ts;
if ( typeof options.jsx === 'string' ) {
options.jsx = jsxOptions[ options.jsx ] || ts.JsxEmit.None;
}
options = assign( {
noEmitHelpers: true,
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.ES6,
sourceMap: true
}, options );
return {
load ( id ) {
if ( id === 'typescript-helpers' ) {
return helpersTemplate;
}
},
resolveId ( importee: string, importer: string ): string {
// Handle the special `typescript-helpers` import itself.
if ( importee === 'typescript-helpers' ) return 'typescript-helpers';
if ( !importer ) return null;
var result = typescript.nodeModuleNameResolver( importee, importer, resolveHost );
if ( result.resolvedModule && result.resolvedModule.resolvedFileName ) {
if ( endsWith( result.resolvedModule.resolvedFileName, '.d.ts' ) ) {
return null;
}
return result.resolvedModule.resolvedFileName;
}
return null;
},
transform ( code: string, id: string ): { code: string, map: any } {
if ( !filter( id ) ) return null;
const transformed = typescript.transpileModule( fixExportClass( code, id ), {
fileName: id,
reportDiagnostics: true,
compilerOptions: options
});
const diagnostics = transformed.diagnostics.filter( goodErrors );
let fatalError = false;
diagnostics.forEach( diagnostic => {
var message = typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
if ( diagnostic.file ) {
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition( diagnostic.start );
console.error( `${diagnostic.file.fileName}(${line + 1},${character + 1}): error TS${diagnostic.code}: ${message}` );
} else {
console.error( `Error: ${message}` );
}
if ( diagnostic.category === ts.DiagnosticCategory.Error ) {
fatalError = true;
}
});
if ( fatalError ) {
throw new Error( `There were TypeScript errors transpiling "${id}"` );
}
return {
// Always append an import for the helpers.
code: transformed.outputText +
`\nimport { __extends, __decorate, __metadata, __param, __awaiter } from 'typescript-helpers';`,
// Rollup expects `map` to be an object so we must parse the string
map: JSON.parse(transformed.sourceMapText)
};
}
};
}
开发者ID:RReverser,项目名称:rollup-plugin-typescript,代码行数:93,代码来源:index.ts
注:本文中的rollup-pluginutils.createFilter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论