一个人如何编写gulp的resolve.alias函数? [英] How would one write a resolve.alias function for gulp?

查看:242
本文介绍了一个人如何编写gulp的resolve.alias函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Gulp和Tape而不是Webpack和Tape来运行我的测试套件.原因是速度和简单性. Gulp功能性任务方法,而不是在捆绑时进行测试.

I'm using Gulp and Tape to run my test suite instead of Webpack and Tape. The reason is for speed and simplicity. Gulp functional task approach instead of testing while bundling.

现在,为了使其正常工作,我需要解析导入文件的路径.

Now, in order for it to work I need to resolve a file path for an import.

在webpack中,我将使用:

In webpack I would use:

resolve: {
   alias: {
      'machingWord' : __dirname
   }
}

类似这样的内容: https://www.npmjs.com/package/gulp-解决,但不是手动操作.希望任务在测试导入时能够解析导入"...".

So something like this: https://www.npmjs.com/package/gulp-resolve, but not as manual. Want the task to be able to resolve import '...' as it tests it.

我是否可以编写一个自定义gulp.task来接收文件并能够执行此功能?我不熟悉在JS中操作文件本身来做到这一点.

Is there a way for me to write a custom gulp.task to take in the file and be able to do this functionality? i'm not to familiar with manipulating the file itself in JS to do this.

推荐答案

我找到的答案是这个插件: https://www.npmjs.com/package/babel-plugin-module-resolver

I found the answer is this plugin: https://www.npmjs.com/package/babel-plugin-module-resolver

这是一个小问题,但是可以解决问题.按照说明进行操作.

It's a little buggy, but it does the trick. Follow the instructions and it will do that job.

这篇关于一个人如何编写gulp的resolve.alias函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆