首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在TypeScript中使用gulp插件?

如何在TypeScript中使用gulp插件?
EN

Stack Overflow用户
提问于 2018-11-28 05:48:38
回答 1查看 356关注 0票数 4

我没有在gulp-load-plugins中找到TypeScript的例子。不幸的是,我的TypeScript太差了,无法理解,应该从TypeScript评论中做些什么。

我试过:

代码语言:javascript
复制
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行):

代码语言:javascript
复制
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上说的

代码语言:javascript
复制
/**
 * Extend this interface to use Gulp plugins in your gulpfile.js
 */
interface IGulpPlugins {
}

我试过:

代码语言:javascript
复制
interface IGulpPlugins {
  pug: () => NodeJS.ReadWriteStream;
}

它还界定:

代码语言:javascript
复制
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熟练程度来说,这是我所了解的全部,但是仅仅理解如何在TypeScript中使用gulp-load-plugins还不够。

EN

回答 1

Stack Overflow用户

发布于 2018-12-12 01:37:02

gulp-load-plugins-tests.ts中有一个工作示例

代码语言:javascript
复制
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:不要绑定webpack项目的Node.js依赖关系,这些项目的目标是Node.js (不是浏览器)。webpack-节点-外部会告诉webpack不要捆绑Node.js库,但是仍然可以像往常一样导入和使用它们。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53512923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档