Customize output path of converted files by Gulp markdown it

Asked

Viewed 75 times

1

I was keeping up this step by step, and then came the need for the markdown files converted to html to be in another folder.

View the file code gulpfile.js:

var gulp = require('gulp');
var markdown = require('gulp-markdown-it');

gulp.task('markdown', function() {
    return gulp.src('**/*.md')
        .pipe(markdown())
        .pipe(gulp.dest(function(f) {
            return f.base;
        }));
});

gulp.task('default', ['markdown'], function() {
    gulp.watch('**/*.md', ['markdown']);
});

Consider the following project structure:

 meuProjeto
 |_ .vscode
 |  |_ tasks.json
 |_ folder1
 |  |_ fileA.md
 |_ node_modules
 |_ gulpfile.js
 |_ package-lock.json
 |_ sample.md

When I place the task to perform, after some change in the files .md, I have the following result:

 meuProjeto
 |_ .vscode
 |  |_ tasks.json
 |_ folder1
 |  |_ fileA.html
 |  |_ fileA.md
 |_ node_modules
 |_ gulpfile.js
 |_ package-lock.json
 |_ sample.html
 |_ sample.md

Note that the files .html are along with the original files .md. My goal is to separate them as follows in a folder build:

 meuProjeto
 |_ .vscode
 |  |_ tasks.json
 |_ build
 |  |_sample.html
 |  |_ folder1
 |     |_ fileA.html
 |_ folder1
 |  |_ fileA.md
 |_ node_modules
 |_ gulpfile.js
 |_ package-lock.json
 |_ sample.md

It would be great if folders were created automatically.

I tried to change the Gulp task code, but I didn’t succeed. It’s really possible to do what I want?

1 answer

0


Enough in function gulp.dest return the desired folder. It is still possible to specify some folder to ignore:

gulp.task('markdown', function() {
    return gulp.src(['**/*.md', '!node_modules/**'])
        .pipe(markdown())
        .pipe(gulp.dest('build'));
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.