在src/目录中放置一个主页(index.html),如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- build:css styles/index.css -->
<link rel="stylesheet" href="styles/index.css">
<!-- endbuild -->
</head>
<body></body>
</html>和一个CSS文件(index.css in styles/ dir.)例如:
body {
background-color: red;
}我配置了一个Gulp任务,它将CSS文件与HTML文件链接起来:
const gulp = require('gulp'),
injStr = require('gulp-inject-string'),
useref = require('gulp-useref');
gulp.task('default', () => {
const tab = ' ',
nl = '\n',
nlTab = nl + tab;
return gulp.src('src/index.html')
//.pipe(injStr.before('</head>', tab + '<!-- build:css styles/index.css -->' + nlTab + '<link rel="stylesheet" href="styles/index.css">' + nlTab + '<!-- endbuild -->' + nl))
.pipe(useref())
.pipe(gulp.dest('.tmp/'));
});如果执行Gulp,则将所有注释内容转换为<link rel="stylesheet" href="styles/index.css">。好吧,这很正常。
当我想要简化它时,问题就会发生,避免用HTML手动编写注释。取消对JS源代码的注释(第10行),删除HTML中的注释(8-10),然后再次执行。吞咽用户什么都不做!转化不起作用。为什么!?
发布于 2022-09-29 14:02:15
我发现了解决办法!:
回车字符不见了。使用'\r\n'而不是孤独的'\n'。
https://stackoverflow.com/questions/73840483
复制相似问题