nrm模塊、gulp模塊下載完成后就下載gulp的htmlmin插件,以及相關專案源檔案、輸出檔案都準備完畢后就開始運行壓縮html的代碼:

運行完之后就報錯
[19:43:57] Using gulpfile D:\WEB前端\案例\Node.js\gulp-demo\gulpfile.js
[19:43:57] Starting 'htmlmin'...
[19:43:57] 'htmlmin' errored after 4.57 ms
[19:43:57] TypeError: html.indexOf is not a function
以下是我gulpfile.js中的相關代碼,大佬們可以看看。
// 引入gulp模塊
const gulp = require('gulp');
// 引入htmlmin檔案壓縮插件
const htmlmin = require('htmlmin');
// 通過gulp模塊呼叫task方法創建htmlmin檔案壓縮任務 htmlmin是任務名字 后面跟回呼函式
gulp.task('htmlmin', () => {
console.log('?')
gulp.src('./src/*.html')
// 呼叫htmlmin方法壓碩訓取s的檔案
.pipe(htmlmin({ collapseWhitespace: true }))
// 通過gulp模塊呼叫dest方法輸出壓縮后的檔案
.pipe(gulp.dest('dist'))
})
我的gulp下載的是4.0.2版本的,百度了有人遇到類似的問題但是跟我的不太一樣只是報錯資訊有點類似,答主更改了gulp的版本為3.9版本就解決了,我試了這個方法但是沒卵用。
以下是一開始的版本資訊:

在執行引入htmlmin插件的代碼段中htmlmin前面有三個小點... 滑鼠經過提示資訊如下:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/283631.html
標籤:JavaScript
