简体   繁体   English

如何在TypeScript中使用gulp-load-plugins?

[英]How to use gulp-load-plugins with TypeScript?

I found no examples for gulp-load-plugins in TypeScript. 我在TypeScript中找不到gulp-load-plugins例子。 Unfortunately, my TypeScript is too poor to understand, what should to do from @type/gulp-load-plugins comments. 不幸的是,我的TypeScript太难以理解,应该从@type / gulp-load-plugins注释中做些什么。

I tried: 我试过了:

import * as _gulpPlugins from 'gulp-load-plugins';
const gulpPlugins: IGulpPlugins = _gulpPlugins();

return gulp.src(sourceFilesGlobSelections)
        .pipe(gulpPlugins.pug())
        // ...

It makes 4 warnings from Webpack (I dont understand where number such 75:13-25 refers; .pipe(gulpPlugins.pug()) is on 50 row): 它从Webpack发出4个警告(我不明白75:13-25所指的数字; .pipe(gulpPlugins.pug())是50行):

WARNING in ../node_modules/gulp-load-plugins/index.js 75:13-25
Critical dependency: the request of a dependency is an expression
 @ ./TaskManagers/MarkupPreprocessingHelper.ts

WARNING in ../node_modules/gulp-load-plugins/index.js 81:48-63
Critical dependency: the request of a dependency is an expression
 @ ./TaskManagers/MarkupPreprocessingHelper.ts

WARNING in ../node_modules/gulp-load-plugins/index.js 117:40-55
Critical dependency: the request of a dependency is an expression
 @ ./TaskManagers/MarkupPreprocessingHelper.ts

WARNING in ../node_modules/gulp-load-plugins/index.js 122:51-66
Critical dependency: the request of a dependency is an expression
 @ ./TaskManagers/MarkupPreprocessingHelper.ts

It was told in @types/gulp-load-plugins : 它在@types/gulp-load-plugins被告知:

/**
 * Extend this interface to use Gulp plugins in your gulpfile.js
 */
interface IGulpPlugins {
}

I tried: 我试过了:

interface IGulpPlugins {
  pug: () => NodeJS.ReadWriteStream;
}

It also defined: 它还定义了:

declare module 'gulp-load-plugins' {

    interface IOptions {
        // ...
    }

    interface IPluginNameMappings {
        [npmPackageName: string]: string
    }

    /** Loads in any gulp plugins and attaches them to an object, freeing you up from having to manually require each gulp plugin. */
    function gulpLoadPlugins<T extends IGulpPlugins>(options?: IOptions): T;

    // ...
}

It looks like maybe I should use gulpLoadPlugins instead of interface extending ... Is is all that I understand with my current TypeScirpt proficiency, but it not enough to understand how to use gulp-load-plugins in TypeScript. 看起来我可能应该使用gulpLoadPlugins而不是接口扩展......我理解当前的TypeScirpt熟练程度,但这还不足以理解如何在TypeScript中使用gulp-load-plugins

There is the working example in gulp-load-plugins-tests.ts : gulp-load-plugins-tests.ts中有一个工作示例:

import * as gulp from 'gulp';
import gulpConcat = require('gulp-concat');
import gulpLoadPlugins = require('gulp-load-plugins');

interface GulpPlugins extends IGulpPlugins {
    concat: typeof gulpConcat;
}

gulp.task('taskName', () => {
    gulp.src('*.*')
        .pipe(plugins.concat('concatenated.js'))
        .pipe(gulp.dest('output'));
});

About Critical dependency: the request of a dependency is an expression : do not bundle Node.js dependencies for the webpack projects those target is Node.js (not browser). 关于Critical dependency: the request of a dependency is an expression :不要为webpack项目捆绑Node.js依赖关系,那些目标是Node.js(不是浏览器)。 webpack-node-externals will tell webpack do not bundle Node.js libraries, however it's still possible to import and use them as usual. webpack-node-externals将告诉webpack不捆绑Node.js库,但是仍然可以像往常一样导入和使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM