我正在尝试构建一个gulp管道 - 我想向我注入一些CSS index.html(这很好),然后从源中获取所有其他链接index.html并在输出版本中替换它们.
我注意到,如果要替换的模板化部分包含HTML注释,则useref调用会破坏输出(请参阅下面的示例).用代码演示最简单:COMMENT
index.html (源文件)<!-- build:css styles/app.css-->
<!--COMMENT-->
<link rel="stylesheet" href="/.tmp/styles.css">
<!-- endbuild -->
Run Code Online (Sandbox Code Playgroud)
gulpfile.js 任务gulp.task('optimizeReplace', function () {
var assets = $.useref.assets({ searchPath: './' });
return gulp
.src('./src/client/index.html')
.pipe(assets)
.pipe(assets.restore())
.pipe($.useref()) //THIS IS THE PROBLEM LINE; IF INJECT IS NOT RUN FIRST IT IS MANGLED
.pipe(gulp.dest('./wwwroot/'));
});
Run Code Online (Sandbox Code Playgroud)
index.html)</style>
<link rel="stylesheet" href="styles/lib.css">
<link rel="stylesheet" href="styles/app.css-->" <!--COMMENT>
</head>
<body>
<div>
Run Code Online (Sandbox Code Playgroud)
这个问题在HTML中更容易看到,但COMMENTHTML注释会丢失其标记的结尾部分,因此它之后的所有内容都认为它是一个注释.
我想在替换部分中添加注释的原因是注释实际上是一个 …
重命名我的文件后,我在运行gulp构建任务时收到以下错误:
Error: Error: File not found with singular glob: F:\Projects\xyz\HTML\app\css\main.css
at DestroyableTransform.<anonymous> (F:\Projects\xyz\HTML\node_modules\gulp-useref\lib\streamManager.js:90:36)
Run Code Online (Sandbox Code Playgroud)
main.css文件不再存在,因为我将其更改为style.css但由于某种原因它正在搜索旧文件.
我刚刚开始使用Yeoman来构建一个新的Angular应用程序.我按照generator-angular的安装指南,但选择使用gulp而不是grunt作为任务运行器.
安装后我收到错误:task 'wiredep' is not in you gulpfile.
我尝试使用运行构建gulp并收到错误:TypeError: $.useref.restore is not a function
如果我运行gulp serve,结果页面不会连接依赖项.
是否修复了上述错误?
我注意到Yeoman使用grunt,并且gulp是实验性的,所以我猜想上面的错误是预期的.我应该在生成器的GitHub页面上将其作为问题发布吗?
yeoman yeoman-generator gulp yeoman-generator-angular gulp-useref
这是我的缩小gulp任务:
var gulp = require('gulp'),
useref = require('gulp-useref'),
gulpif = require('gulp-if'),
uglify = require('gulp-uglify'),
minifyCss = require('gulp-minify-css'),
ngmin = require('gulp-ngmin'),
ngAnnotate = require('gulp-ng-annotate');
gulp.task('minifyAll', function () {
return gulp.src('app/*.html')
.pipe(useref())
.pipe(gulpif('*.js', uglify(ngAnnotate())))
.pipe(gulpif('*.css', minifyCss()))
.pipe(gulp.dest('dist'));
});
Run Code Online (Sandbox Code Playgroud)
在js-file的情况下,我想首先通过ng-annotate和uglify移动它.我是新手,这就是为什么我不知道如何正确地做到这一点.
我正在运行一些html文件我模板引擎,所有资产都声明如下:
<link rel="stylesheet" href="$href('libs/bootstrap.min.css')">
<script src="$href('libs/jquery.js')"></script>
当我运行$ .useref时,它确实会将文件移动到正确的文件夹中,但会将.html文件保留为通常应具有的绝对路径和相对路径.有没有办法可以编辑$ .useref"template"来指向正确位置的脚本和链接标签,并在src和href属性中添加/附加$ href('')?有没有其他gulp插件可以做到这一点?
我想用django使用gulp-useref.我的所有注入脚本都工作正常,注入后进行手动路径更新,但现在我想连接我注入的脚本.这是我的HTML
<!-- build:css({compile/serve,src}) styles/vendor.css -->
<!-- bower:css -->
<link rel="stylesheet" href="{{ STATIC_URL }}dash/bower_components/angular-material/angular-material.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}dash/bower_components/nvd3/src/nv.d3.css" />
<!-- endbower -->
<!-- endbuild -->
<!-- build:css({compile/serve,src}) styles/app.css -->
<!-- inject:css -->
<link rel="stylesheet" href="{{ STATIC_URL }}dash/compile/serve/styles/main.css">
<!-- endinject -->
<!-- endbuild -->
Run Code Online (Sandbox Code Playgroud)
和
<!-- build:js(src) scripts/vendor.js -->
<!-- bower:js -->
<script src="{{ STATIC_URL }}dash/bower_components/angular/angular.js"></script>
<script src="{{ STATIC_URL }}dash/bower_components/angular-animate/angular-animate.js"></script>
<script src="{{ STATIC_URL }}dash/bower_components/angular-cookies/angular-cookies.js"></script>
<script src="{{ STATIC_URL }}dash/bower_components/angular-touch/angular-touch.js"></script>
<script src="{{ STATIC_URL }}dash/bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="{{ STATIC_URL }}dash/bower_components/angular-resource/angular-resource.js"></script>
<script src="{{ STATIC_URL }}dash/bower_components/angular-route/angular-route.js"></script> …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 heroku 构建一个 Angular 应用程序,每当它达到 html 构建状态时,我都会收到此错误。这是我第一次部署到 heroku,但在过去的几天里,当应用程序在我的本地机器和服务器上运行没有任何问题时,我不断收到不同的错误。
TypeError: $.useref.assets is not a function
2017-04-18T14:36:18.895917+00:00 app[web.1]: at Gulp.<anonymous> (/app/gulpfile.js:55:25)
2017-04-18T14:36:18.895918+00:00 app[web.1]: at module.exports (/app/node_modules/orchestrator/lib/runTask.js:34:7)
2017-04-18T14:36:18.895919+00:00 app[web.1]: at Gulp.Orchestrator._runTask (/app/node_modules/orchestrator/index.js:273:3)
2017-04-18T14:36:18.895920+00:00 app[web.1]: at Gulp.Orchestrator._runStep (/app/node_modules/orchestrator/index.js:214:10)
2017-04-18T14:36:18.895920+00:00 app[web.1]: at /app/node_modules/orchestrator/index.js:279:18
2017-04-18T14:36:18.895921+00:00 app[web.1]: at finish (/app/node_modules/orchestrator/lib/runTask.js:21:8)
2017-04-18T14:36:18.895922+00:00 app[web.1]: at /app/node_modules/orchestrator/lib/runTask.js:52:4
2017-04-18T14:36:18.895922+00:00 app[web.1]: at f (/app/node_modules/end-of-stream/node_modules/once/once.js:17:25)
2017-04-18T14:36:18.895923+00:00 app[web.1]: at DestroyableTransform.onend (/app/node_modules/end-of-stream/index.js:31:18)
2017-04-18T14:36:18.895924+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-04-18T14:36:18.895924+00:00 app[web.1]: at DestroyableTransform.emit (events.js:185:7)
2017-04-18T14:36:18.895925+00:00 app[web.1]: at /app/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:965:16
2017-04-18T14:36:18.895925+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:73:7)
2017-04-18T14:36:18.895926+00:00 app[web.1]: at process._tickCallback …Run Code Online (Sandbox Code Playgroud)