将Gulp编译为父文件夹

时间:2017-12-21 10:19:00

标签: sass gulp pug

我知道之前已经问过这个问题但是给出的答案似乎没有起作用。我已经检查了GULP文档和GitHub Gulp。我的Gulp拒绝编译到特定文件夹。这是我的项目结构

Parent [contains gulpfile.js]
|_src
   |_assets
       |_jade
       |_sass
       |_scripts

这是我的gulpfile.js

var gulp = require('gulp');
var ts = require('gulp-typescript');
var pug = require('gulp-pug');
var sass = require('gulp-sass');

// == PATH STRINGS ========
var paths = {
    typescript: './src/**/*.ts',
    pug: 'src/assets/pug/*.pug',
    sass: 'src/assets/sass/*.scss',
    distScripts: 'src/scripts',
    distPug: '../../src',
    distSass: 'src'
};

// == TYPESCRIPT ========
gulp.task('typescript', function () {
    return gulp.src(paths.typescript)
        .pipe(ts({
            noImplicitAny: true,
            outFile: 'output.js'
        }))
        .pipe(gulp.dest(paths.distTypescript));
});

// == pug ===============
gulp.task('pug', function() {
  gulp.src(paths.pug)
    .pipe(pug({}))
    .pipe(gulp.dest('../../src'))
});

// == SASS ==============
gulp.task('sass', function () {
    return gulp.src(paths.sass)
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest(paths.distSass));
});

// == COMPILE SYNCHRONOUSLY
gulp.task('watch', function () {
  gulp.watch(paths.typescript, ['typescript']);
  gulp.watch(paths.pug, ['pug']);
  gulp.watch(paths.sass, ['sass']);
});

我只想将我的sass和pug文件编译为 src 文件。非常感谢您的帮助或帮助!

1 个答案:

答案 0 :(得分:-1)

我自己设法回答了这个问题。感谢大家。我需要做的就是指定直接路径而不是使用通用选择器

var gulp = require('gulp');
var ts = require('gulp-typescript');
var pug = require('gulp-pug');
var sass = require('gulp-sass');

// == PATH STRINGS ========
var paths = {
    typescript: './src/**/*.ts',
    pug: 'src/assets/pug/*.pug',
    sass: 'src/assets/sass/*.scss',
    distTypescript: 'src/scripts',
    distPug: 'src',
    distSass: 'src'
};

// == TYPESCRIPT ========
gulp.task('typescript', function () {
    return gulp.src(paths.typescript)
        .pipe(ts({
            noImplicitAny: true,
            outFile: 'output.js'
        }))
        .pipe(gulp.dest(paths.distTypescript));
});

// == pug ===============
gulp.task('pug', function() {
  gulp.src(paths.pug)
    .pipe(pug({}))
    .pipe(gulp.dest(paths.distPug))
});

// == SASS ==============
gulp.task('sass', function () {
    return gulp.src(paths.sass)
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest(paths.distSass));
});

// == COMPILE SYNCHRONOUSLY
gulp.task('watch', function () {
  gulp.watch(paths.typescript, ['typescript']);
  gulp.watch(paths.pug, ['pug']);
  gulp.watch(paths.sass, ['sass']);
});