吞咽useref。无法读取未定义的属性“替换”

时间:2019-04-13 21:23:24

标签: javascript gulp

我需要简单的gulp任务来丑化我的js文件并将其移动到dist文件夹。根据文档,我做了:

gulp.task('useref', function(){ //uglify js
  return gulp.src('app/*.html')
    .pipe(useref())
    .pipe(gulpIf('app/js/*.js', uglify()))
    .pipe(gulp.dest('dist'))

});

package.json

"devDependencies": {
    "browser-sync": "^2.26.3",
    "gulp": "^4.0.0",
    "gulp-cache": "^1.1.1",
    "gulp-imagemin": "^5.0.3",
    "gulp-sass": "^4.0.2",
    "gulp-uglify": "^3.0.2",
    "gulp-useref": "^3.1.6",
    "concat": "^1.0.3",
    "del": "^4.1.0",
    "gulp-cssnano": "^2.1.3"
  },

当我启动'gulp useref'时,我总是会出错:

TypeError: Cannot read property 'replace' of undefined
   at module.exports (E:\Downloads\n\node_modules\useref\lib\getBlocks.js:31:20
)
    at module.exports (E:\Downloads\n\node_modules\useref\index.js:8:16)
    at E:\Downloads\n\gulpfile.js:26:11
    at taskWrapper (E:\Downloads\n\node_modules\undertaker\lib\set-task.js:13:15
)
    at bound (domain.js:396:14)
    at runBound (domain.js:409:12)
    at asyncRunner (E:\Downloads\n\node_modules\async-done\index.js:55:18)
    at process._tickCallback (internal/process/next_tick.js:61:11)

文件夹结构:

 | -app/
       | - css/
       | - fonts/
       | - images/
       | - index.html
       | - js/
                   | - jScript.js
       | - scss/
 | - dist/
 | - gulpfile.js
 | - node_modules/
 | - package.json

我错了吗?

0 个答案:

没有答案