Reputation: 8508
My html files are located in folders and subfolders and sub-sub-folders. I want to use Gulp to minify the html files and save the results in a folder structor similar to the folder structure of original html files.
I found this response in stack overflow, but it gives me error. Here is the error message:
ReferenceError: configHTML is not defined
I also asked chatGPT and it gave me this answer, but it is not doing anything when I run. Here is the answer:
const gulp = require('gulp');
const htmlmin = require('gulp-htmlmin');
const rename = require('gulp-rename');
const recursiveFolder = require('gulp-recursive-folder');
const ignore = require('gulp-ignore');
function minifyHTML() {
return gulp.src(['src/**/*.html', 'src/*/**/*.html', 'src/*/*/**/*.html']) // Path to your HTML files
.pipe(ignore.exclude('*.min.html')) // Exclude already minified files
.pipe(htmlmin({ collapseWhitespace: true })) // Minify HTML
.pipe(rename({ extname: '.min.html' })) // Rename files with .min.html extension
.pipe(gulp.dest('dist')); // Destination folder
}
exports.minifyHTML = minifyHTML;
and it says to run the above by: gulp minifyHTML
.
What is wrong with the above codes ad how can I achieve what I am looking for?
Upvotes: 0
Views: 61