我们有多个独立的 ui 模块(独立的 git 项目)。我们正在使用 npm 下载 gulp 的开发依赖项,然后 gulp 预编译 sass、uglify js、构建模板 cash、运行本地 lint 和测试。这意味着每个模块都有几乎相同的 package.json 和 gulpfile.js。有没有办法重新使用它们,引用它们而不是在每个项目中复制它们?或者像 Maven 那样从父级继承设置和配置?
最佳答案
是的,绝对有。
在我现在工作的项目中,我们遇到了完全相同的情况:前端模块被分成不同的存储库,并且具有非常相似的 gulp 任务集。因此,我们已将这些任务移至 gulp-common
存储库,并通过 npm 将其安装为开发依赖项:
"devDependencies": {
"gulp-common": "git+ssh://our-repo-url/gulp-common.git"
}
然后,为了加载这些 gulp 任务,我们修改了 gulpfile.js
,现在它看起来像这样:
require('require-dir')('build/tasks'); // load specific tasks from the usual place
require('require-dir')('node_modules/gulp-common/build/tasks'); // load common tasks
同时,在 gulp-common 中,我们有一个包含任务的 ./build
目录和一个 index.js
文件:
module.exports = require('require-dir')('./build');
干杯!
关于javascript - 有没有办法(从远程位置)引用 gulpfile.js 和 package.json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35177533/