2017-12-07 11 views
0

과 폴더를 병합 : 나는 상속과 말대꾸 파일을 컴파일하는 방법을 찾고 있어요꿀꺽의 말대꾸 : (간체) 나는이 같은 폴더 구조를 가지고 파일 상속

|-project1 
|--_file1.scss 
|--_file2.scss 
|--_file3.scss 
| 
|-project2 
|--_file2.scss 
| 
|-css 
|--project1.css 
|--project2.css 

. 이 기본 개념은 기본 프로젝트 (project1)가 있고 프로젝트 2는 변경해야하는 파일 만 포함한다는 것입니다.

컴파일 꿀꺽 2 개 CSS 파일을 렌더링해야합니다 그래서시 :

  1. project1.css 이 프로젝트 1/SCS들/폴더이 하나의 파일 1을 포함해야

  2. project2.css에서 파일 만 포함을 프로젝트 1의 file3과 프로젝트 2의 file2.

이것이 가능합니까? 필요한 모듈은 무엇입니까?

고맙습니다.

답변

0

다음은 유용한 항목입니다. 프로젝트 폴더에 개의 부분이 (예 : _file1.scss, _file2.scss 등) 인 것으로 나타났습니다. 그 중 일부는 가져 오지 않아서 하나 이상의 파일을 가져야합니다.

const gulp = require('gulp'); 
const fs = require('fs'); 
const path = require('path'); 

const filter = require('gulp-filter'); 
const sass = require('gulp-sass'); 
const concat = require('gulp-concat'); 
const addsrc = require('gulp-add-src'); 

// const glob = require("glob"); 

const sources = ['project1', 'project2', 'project3']; 
    // could glob your sourceFolders with something like 
    // const sources = glob.sync("project*"); 
const filterSources = Object.keys(sources); 

function isUnique(file, index) { 

    console.log(path.basename(file.path)); // file1.scss, file2.scss, etc. all from project1 

    baseName = path.basename(file.path); 
    folder = sources[index]; // project 

    // does that basename exist in thecurrent project (sources[index]) 
    return !fs.existsSync(folder + path.sep + baseName); 
} 

gulp.task('default', function() { 

     // loop through all the project folders 
    filterSources.forEach(function (project, index) { 

    const f = filter(function (file) { 
     return isUnique(file, index); 
    }); 

    // always using project1 files as basis 
    const stream = gulp.src('./project1/*.scss') 

     // filter out from the source stream (project1 files) any files that appear in the current project directory 
     .pipe(f) 

     // add all files from the current project directory, i.e., project2, project3, etc. 
     .pipe(addsrc.append('./' + sources[index] + '/*.scss')) 

     .pipe(sass().on('error', sass.logError)) 

     // give the concat the filename of the current project 
     .pipe(concat(sources[index] + '.css')) 

     .pipe(gulp.dest('css')); 

    return stream; 
    }); 

이것은 단지 다른 수입이 아닌 부분하는 SCS 파일 필터링 하나가 아닌지 확인, 프로젝트 폴더의 번호를 사용할 수 있습니다.

concat 각 프로젝트마다 모든 파일이 있으므로 각 파일 이름에서 앞에 오는 밑줄을 제거해야하기 때문에 어쨌든 일부 부분을 원하지 않는 것처럼 보입니다.

+0

감사합니다. 당신은 확실히 나를 올바른 방향으로 밀어 넣었습니다. 귀하는 부분적인 부분에 대해 어느 정도 권리가 있습니다. 그것이 magento 프로젝트이기 때문에 시스템은 무엇을 포함하고 무엇을 포함하지 않을지 신경 쓸 수 있습니다. 불행히도 나는 기초 프로젝트에서 일하려고 애를 쓰고 있으며 partial을 사용하지 않는 것이 불가능한 것처럼 보인다. 나는 sass 레벨 (@import)에서이 상속을 할 수 있었으면 좋겠다. –