且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

gulp-useref引发错误:“路径必须是字符串”

更新时间:2023-11-05 15:24:22

Short answer: TypeError: path must be a string means that there is an issue with the link/script paths. useref can't find the the file or directory you are pointing it to.

Long answer:
There were two issues I ran into.

  1. The link/script paths needs to be relative to the gulpfile or have an alternate directory to search.

<!-- build:css /styles/main.css -->
<link href="app/styles/base.css">
<link href="app/styles/article.css">
<!-- endbuild -->

OR

<!-- build:css(app) /styles/main.css -->
<link href="/styles/base.css">
<link href="/styles/article.css">
<!-- endbuild -->

  1. The yeoman gulpfile uses multiple alt directories which requires you to put them inside curly braces like this:

<!-- build:css({.temp,app}) /styles/main.css --> Works

But if you only have one alt directory and you leave it in the curly braces it will throw an error.

<!-- build:css({app}) /styles/main.css --> TypeError: path must be a string

This is because it is reading the path as C:\path\to\project\{app}\styles\style.css. This seems like odd behavior to me. I would think that it would iterate through the directories listed in the braces regardless of the length.

相关阅读

推荐文章