问题标签 [gulp-useref]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
asp.net-mvc - Bundling and concatenation with gulp-useref Durandal and ASP.NET MVC
I have a Durandal 2
app based on ASP.NET MVC 5
and Web API
, with the initial Index.cshtml
(on HomeController
) being served through the MVC router. From then on it's all regular html views being handled by the Durandal router.
Anyway, I'm trying to use gulp-useref to concatenate all css
and js
files. I've got everything working and gulp-useref
drops the newly concatenated files and an index.cshtml
with the updated script and stylesheet references in a dist
folder.
Of course, for the application to work I need the updated index.cshtml
back in Views/Home/
. I have created a "copy" task with gulp
that does just that; it overwrites the original index.cshtml
and fixes the paths to the concatenated js
and css
files.
That works as well, but since useref
removes the html comments that mark the spot where it should insert the references to the concatenated files, the process is not repeatable.
Let me illustrate with some code.
In my Index.cshtml
I have:
This is where gulp-useref
will place the updated script reference so it will end up looking like this:
As you can see, useref
removes the html comments so if I overwrite the original index.cshtml
with this file, useref
will not know where to place the updated script tag. And if I don't overwrite the original index.cshtml
, the application will not be using the concatenated files.
I'm new to gulp
so I might be going at this in the completely wrong way, but how can I make sure that my /Views/Home/index.cshtml
uses the concatenated files in an automated manner?
Or, alternatively, is there a better approach for what I'm trying to do, namely, get everything ready for deployment?
Here are my relevant gulp
tasks, for reference:
gulp - gulp-useref:更新查找路径并在使用 .restore 函数之前添加某个变量
我正在尝试将 gulp-useref 与 django 一起使用。我所有的注入脚本都工作正常,注入后进行手动路径更新,但现在我想连接我注入的脚本。这是我的html
和
我只想{{ STATIC_URL }}dash
从路径中删除,因为这是我的 gulpfile.js 所在的根目录(不同于 index.html 目录),将脚本处理到相应的文件中,然后使用编译 css 和 js 更新我的 index.html ..但预先{{ STATIC_URL }}dash
gulp - 如果文件超过 25 个,gulp-useref 将忽略文件
我正在使用generator-gulp-webapp并将 27 个 html 文件编译到该.tmp
文件夹中。dist
我发现只有前 25 个 html 文件将在 gulp-useref 任务期间被处理并传递到文件夹。这是gulpfile.coffee
's 的代码,真的需要知道如何解决这个问题,谢谢。
javascript - Why does gulp-useref does not seem to work with a comment in the replacement section?
I am trying to build a gulp pipeline – I want to inject some CSS into my index.html
(this works fine) and then grab all the other links from source index.html
and replace them in the outputted version.
I noticed that the useref
call is mangling the output if the templated section to replace includes an HTML comment (see example below for the line COMMENT
). It’s easiest to demonstrate with code:
index.html
(source file)
gulpfile.js
task
Output (index.html
)
The problem is easier to see in HTML, but the COMMENT
HTML comment looses the end half of its tag, so everything after it thinks it is a comment.
The reason I want to put a comment inside the replacement section is that the comment is actually a gulp-inject statement which injects some other references before I do the useref
. I simplified it down to a simple HTML comment causing the problem.
This is the line that causes the problem: .pipe($.useref())
FYI I am following John Papa’s course on Pluralsight where he uses this exact mechanism to inject some CSS and then replace them – (the inject:css
HTML comment delimiters are mangled after a useref
):
How can I get the useref()
to replace the template with the correct links but leave the HTML comment intact?
Thanks.
gulp - gulp-useref 不会将我的远程托管文件构建到 min.js
嗨,我尝试将所有 css 和 js 构建到 /dist/ 中,但我只有本地文件...为什么 useref 不下载并将我的 jquery cdn 从 google 放入 ma min.js
请有解决方案(我真的不想使用包管理器作为凉亭)我更喜欢 gulp-useref 做这项工作......想法?
gulp - gulp-uglify 创建错误的输出
我正在尝试运行一个任务来缩小我的 index.html 中的其他内容:
但所有 javascript(如 bootstrap.js、respond.js ...)在输出文件中似乎都是错误的。
我做错了什么?
javascript - 使用 gulp.useref 后,gulp.js 将字符串添加到 src 和 href 属性
我在模板引擎中运行一些 html 文件,所有资产都这样声明:
<link rel="stylesheet" href="$href('libs/bootstrap.min.css')">
<script src="$href('libs/jquery.js')"></script>
当我运行 $.useref 时,它确实将文件移动到正确的文件夹中,但将 .html 文件保留为通常应该具有的绝对和相对路径。有没有办法可以编辑 $.useref “模板” 的脚本和链接标签指向正确的位置,并在 src 和 href 属性中添加/附加 $href('') ?有没有其他 gulp 插件可以做到这一点?
javascript - Gulp-useref:按类型有条件地处理资产?
使用 gulp-useref 时,是否可以根据 html 标签内声明的 html 构建类型有条件地处理 css 和 js 资产?
我想做的只是 autoprefix 和 jslint 通过区分它们来区分非供应商资产,就像那样(注意 css 与 css_vendors 类型):
索引.html
gulpfile.js
但不幸的是,这个 gulpfile.js 代码不起作用。
gulp - useref.assets 打破 gulp 管道
当我尝试在我的 index.html 文件上使用 gulp-useref 时,管道中断并且任务无法完成它有什么问题?我的 html 源代码上有 testet useref,这很好
在 useref.assets 之后调试不会显示
javascript - gulp-useref“additionalStreams”不合并
所以我有一个简单的用例,它似乎与https://github.com/jonkemp/gulp-useref自述文件中描述的用例非常相似。
我正在尝试在构建期间使用所有 Angular 模板生成一个 templates.js 文件。我正在尝试这样做并且在我的本地项目中没有 templates.js 文件。所以想法是将模板流的输出合并到 useref 流中,以便生成的scripts.js
文件包含我的索引文件中指示的所有文件和生成的templates
输出。
这是我在 gulp 任务中的内容:
现在这应该允许我合并 templatesStream 的输出并将其全部转换为一个scripts.js
文件,我认为......
我还尝试<script src="scripts/templates.js"></script>
在我的索引文件中放置许多表格来尝试帮助它。似乎没有一个工作。
还有其他人在做同样类型的事情吗?似乎是一个常见的用例。