4

gulp-load-plugins我在 TypeScript 中找不到任何示例。不幸的是,我的 TypeScript 太差了,无法理解,从@type/gulp-load-plugins 评论中应该做什么。

我试过了:

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

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

它从 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

它被告知@types/gulp-load-plugins

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

我试过了:

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

它还定义了:

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;

    // ...
}

看起来也许我应该使用gulpLoadPlugins而不是接口扩展......这就是我目前的 TypeScirpt 熟练程度所了解的全部内容,但还不足以了解如何gulp-load-plugins在 TypeScript 中使用。

4

1 回答 1

1

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'));
});

关于Critical dependency: the request of a dependency is an expression:不要为那些目标是 Node.js(不是浏览器)的 webpack 项目捆绑 Node.js 依赖项。webpack-node-externals会告诉 webpack 不要捆绑 Node.js 库,但是仍然可以像往常一样导入和使用它们。

于 2018-12-12T01:37:02.210 回答