Sass 捕获并重用glob
我是一个刚开始大口大口大口大口编程的人 我需要定义一个“动态”scss任务,它在多个目标目录中编译多个源目录Sass 捕获并重用glob,sass,gulp,Sass,Gulp,我是一个刚开始大口大口大口大口编程的人 我需要定义一个“动态”scss任务,它在多个目标目录中编译多个源目录 src/main/scss/ app.scss(全球资源) 模块/(模块资源) 管理员/ *.scss ftt/ *.scss 上面是源文件的目录布局。 我感兴趣的是将modules目录下的每组scss文件(我可能事先不知道)编译成包含模块本身的目录树 src/main/scss/modules/admin/*.scss ==> webapp/secure/ad
- src/main/scss/
- app.scss(全球资源)
- 模块/(模块资源)
- 管理员/
- *.scss
- ftt/
- *.scss
- 管理员/
src/main/scss/modules/admin/*.scss ==> webapp/secure/admin/common/common.css
src/main/scss/modules/ftt/*.scss==> webapp/secure/ftt/common/common.css
我可以编写一个glob来捕获
src/main/scss/modules/*/*.scss
,但是如何重用表示目录的星型?如果我运行的是regex,我会捕获并使用编号为$1的组,以获得一个较长的工作代码版本,即通过文件夹数组循环,以构建基于文件夹的捆绑包,请参阅
我建议看看glob.sync。在此处搜索
[gulp]glob.sync用户:836330
。那是我。我在这里回答了一些与你类似的问题。请特别注意。它在不同的文件夹上运行相同的gulp任务,然后使用文件夹名称设置唯一的目标
对这样的东西来说很好
伪代码如下(未测试):
const moduleFolders = glob.sync('src/main/scss/modules');
// perhaps your app.scss is supposed to be bundled into each module's css?
// if so, just add a second source to the gulp.src below
const sassSrc = 'common.scss'; // or your main scss file that does the imports in each module
gulp.task('default', () => {
let stream;
// work on each folder separately
moduleFolders.forEach(function (module) {
stream = gulp.src( module + sassSrc )
.pipe(sass())
//.pipe(concat('style.min.css'))
//.pipe(autoprefixer())
//.pipe(cssmin())
.pipe(gulp.dest( "webapp/secure/" + module + '/common' ));
});
return stream;
});