Set gulp-usemin task to build the content of src folder, but not create another src folder into dist

35 views Asked by At

So, I have the follow project structure

├── gulpfile.js
├── output.txt
├── package-lock.json
├── package.json
└── src
   ├── assets
   |  ├── css
   |  ├── img
   |  ├── js
   |  └── pages
   └── index.html

And the follow gulp tasks

gulp.task("imagemin", function () {
    return gulp
        .src("./src/assets/img/*", { base: "." })
        .pipe(
            imagemin({
                optmizationLevel: 1,
                progressive: true,
                interlaced: true
            })
        )
        .pipe(gulp.dest("dist/"));
});

gulp.task("usemin", function () {
    return gulp
        .src("./src/*.html", { base: "." })
        .pipe(
            flatmap(function (stream, file) {
                return stream.pipe(
                    usemin({
                        css: [cleanCss(), rev()],
                        html: [
                            function () {
                                return htmlmin({
                                    collapseWhitespace: true
                                });
                            }
                        ],
                        js: [uglify(), rev()],
                        inlinejs: [uglify()],
                        inlinecss: [cleanCss(), "concat"]
                    })
                );
            })
        )
        .pipe(gulp.dest("dist/"));
});

gulp.task("build", gulp.series("clean", gulp.parallel("imagemin", "usemin")));

When I run build, I get the follow structure:

├── dist
|  └── src
|     ├── assets
|     └── index.html
├── gulpfile.js
├── output.txt
├── package-lock.json
├── package.json
└── src
   ├── assets
   |  ├── css
   |  ├── img
   |  ├── js
   |  └── pages
   └── index.html

But I don't want another src folder into the dist folder, just it's content. How do I do that?

I tried to set ´root: ./src` as usemin task option, but I get the same result.

OBS: The pages folder into assets have more html files.

0

There are 0 answers