问题标签 [gruntjs]

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.

0 投票
2 回答
999 浏览

gruntjs - 自定义 grunt.helper 值可能吗?

我正在使用 grunt 的 CLI 可能性来处理我自己的样板grunt init:webdesign-project文件——为此,我创建了一个在其中命名的文件夹webdesign-projectnode_modules/grunt/init一个相应的webdesign-project.js文件。到目前为止,一切都很好。

现在我想用这样的grunt.helper功能插入我自己的“问题”

然而这给了我

难道不能用这个函数定义自己的变量吗?

编辑:有人知道这个函数的文档是否存在吗?(还没有找到)

0 投票
2 回答
6154 浏览

node.js - 用于漂亮打印 HTML 的模块?

我正在处理一个 grunt 构建文件,它会点击一个 URL 并将输出写入静态 HTML 文件。我点击的网址已压缩 HTML,我想在写入静态文件之前将其打印出来。有没有什么好的模块可以做到这一点?我环顾四周,似乎 Max Ogden 的 html prettyprinter 是我最接近的选择(https://github.com/maxogden/commonjs-html-prettyprinter)。也许如果我将它与 grunt-shell 任务或其他东西结合起来?真的,我更愿意在 grunt 中只需要一个模块并说 pretty(my-file.html) 然后使用 fs 编写它,但到目前为止这被证明是难以捉摸的。

0 投票
4 回答
8834 浏览

javascript - grunt.js - 缩小文件时的多个目的地

我的 grunt.js 有一个典型的缩小任务:

拥有多个 dest 文件的最简单方法是什么?我想缩小为:

  • dist/precook.min.js
  • 示例/js/vendor/precook.min.js

内置的 min 任务似乎不支持多个目的地,所以我认为这可以通过一个简单的“复制”任务来实现。有人可以指出我正确的方向吗?

0 投票
4 回答
6171 浏览

javascript - 我正在尝试 Grunt,需要一种简单的方法来连接我的模块

这是我第一次使用 Grunt,我想让它结合我所有的 js 模块,每个模块都包装在一个立即执行的函数中,包含一个“use strict”声明,并将它们放入一个文件中,只包含在一个立即执行的函数,只有一个“使用严格”声明。

这通常是如何完成的?

我认为这将是一个常见的用例?也许我做错了事?我是否应该使用其中一种模块加载格式(即 commonjs、amd) 所有这些文件将始终一起加载到浏览器中,所以如果人们通常这样做的话,我实际上不介意删除所有立即执行的函数。重要的部分是最终结果以某种方式包装,通过 lint 和单元测试并包含“use strict”声明。

(我应该澄清一下,我确实让它工作,linting,单元测试,连接和缩小,当我在最终的连接文件中看到一堆不必要的立即执行函数时,感觉就像我做错了什么。)

0 投票
2 回答
1288 浏览

windows - sublime text 2 控制台仅显示第一行 gruntjs 输出

在 Windows 上以 sublime text 2 运行 grunt 时,似乎认为它只显示第一行输出。奇怪的是,所有任务都完成了。添加"shell": trueorfalse似乎没有任何效果。添加cmd /c甚至start /wait /b.

如何阻止 sublime text 吃掉其余的输出?

我得到的唯一输出是:

更新 这似乎与 Sublime Text 2 issue 23: Windows Build Panel Eats Stdout有关。

更新 有一个解决方法,但它很难看。

0 投票
4 回答
5088 浏览

javascript - 将 JSLint/Hint 与 requirejs 一起使用

我目前正在为驱动的项目设置自动构建脚本(使用) 。因此,我想在所有需要的文件上运行 / ,然后用 r.js 连接和缩小它。由于 js 文件夹包含很多我不想 lint 的开发文件,我不能只传递给 JSLint。我的第一个想法是运行 r.jsjs/**/*.jsoptimizer: 'none', lint 连接的文件,然后将其缩小,但这不是一个选项,原因有两个。首先它将包含我不想 lint 的供应商库,然后找到有错误的行,找到它的类,在 dev 文件夹中找到适当的 js 文件,在那里修复它,再次运行 r.js,最后 lint再次,这对我们的工作流程来说非常麻烦。因此,我正在寻找一种可能性,将 linting 连接到 r.js 优化器进程中,或者至少以某种方式获取 requirejs 依赖树的列表,我可以对其进行解析并将其传递给 lint。或者任何适用于自动化流程的解决方案,您都会想出。

0 投票
1 回答
1546 浏览

node.js - 在 Ubuntu 12.04 上使用大量 cpu 的 grunt watch

我正在使用 grunt 在 towerjs 项目中查看我的咖啡脚本文件,并在它们更改时重新编译它们。这个配置是由 towerjs 生成的,看起来相当理智。问题是,一旦我开始这个过程,我会看到它与一个 cpu 核心挂钩(实际上,只有一个超线程)。如果我删除了很多被监视的路径,我可以将它降低到 CPU 的 25% 左右,但这仍然非常糟糕。

我发现了一些对一些已知问题的引用以及与 Node 的 fs API 甚至 fs.watch 的跨平台不一致,尤其是. 尝试了grunt-simple-watch但它并没有做得更好。

我可以设置 Guard,但让它正常工作可能会很麻烦,而且功能上的 grunt 似乎也很好 - 我很好奇如果其他人有任何其他建议。

0 投票
2 回答
215 浏览

unit-testing - 如何运行 GruntJS 测试?

我刚刚克隆了gruntjs 存储库

我如何实际运行 GruntJS 的测试?

(我并不是说我想使用 GruntJS 运行我自己的测试。我的意思是我想为 GruntJS 本身运行测试。)

0 投票
1 回答
7764 浏览

html - 使用 grunt js,如何动态添加 to static html files?</h1> <div id="body"><p>More specifically, I want to add the titles by referencing an external JSON file, let's call it titles.json. </p> <p>One of the things I use grunt for is</a> </h3> <div class="s-post-summary--content-excerpt"> </div> <div class="s-post-summary--meta"> <div class="s-post-summary--meta-tags tags js-tags t-cñ t-ûnet t-aspûnet-mvc t-aspûnet-mvc-4 t-actionfilterattribute"> <a href="/tags/html" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">html</a><a href="/tags/json" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">json</a><a href="/tags/build-process" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">build-process</a><a href="/tags/concatenation" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">concatenation</a><a href="/tags/gruntjs" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">gruntjs</a> </div> <div class="s-user-card s-user-card__minimal"> <div class="s-user-card--info"> <div class="s-user-card--link d-flex gs4"> </div> </div> <time class="s-user-card--time" style="margin-left:5px;"> <span title="2022-04-18 08:34:11Z" class="relativetime"> </span></time> </div> </div> </div> </div><div id="question-summary-71909431" class="s-post-summary js-post-summary" data-post-id="71909431" data-post-type-id="1"> <div class="s-post-summary--stats js-post-summary-stats"> <div class="s-post-summary--stats-item s-post-summary--stats-item__emphasized" title="Score of 0"> <span class="s-post-summary--stats-item-number">0</span> <span class="s-post-summary--stats-item-unit">投票</span> </div> <div class="s-post-summary--stats-item " title="1 answers"> <span class="s-post-summary--stats-item-number">1</span> <span class="s-post-summary--stats-item-unit">回答</span> </div> <div class="s-post-summary--stats-item " title="369 views"> <span class="s-post-summary--stats-item-number">369</span> <span class="s-post-summary--stats-item-unit">浏览</span> </div> </div> <div class="s-post-summary--content"> <h3 class="s-post-summary--content-title"> <a href="/questions/13110125" class="s-link">node.js - 使用 compass 命令行编译单个 .scss 文件</a> </h3> <div class="s-post-summary--content-excerpt"> <p>有没有办法通过 compass 命令行实用程序来编译单独的文件?</p> <p>我问的原因是我目前有一个为目录运行 compass compile 命令的 grunt 任务,但是当项目变大并且当一个文件更改时它会尝试编译十几个文件时,这可能会成为一个问题,所以我想看看是否有办法做类似 compass compile app/css/style.scss:app/css/style.css 的事情。</p> </div> <div class="s-post-summary--meta"> <div class="s-post-summary--meta-tags tags js-tags t-cñ t-ûnet t-aspûnet-mvc t-aspûnet-mvc-4 t-actionfilterattribute"> <a href="/tags/node.js" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">node.js</a><a href="/tags/sass" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">sass</a><a href="/tags/compass-sass" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">compass-sass</a><a href="/tags/gruntjs" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">gruntjs</a> </div> <div class="s-user-card s-user-card__minimal"> <div class="s-user-card--info"> <div class="s-user-card--link d-flex gs4"> </div> </div> <time class="s-user-card--time" style="margin-left:5px;"> <span title="2022-04-18 08:34:11Z" class="relativetime"> </span></time> </div> </div> </div> </div> </div> <br class="cbt"> <div class="s-pagination site1 themed pager float-left"> <a class="s-pagination--item js-pagination-item " href="/tags/gruntjs?p=1" rel="" title="Go to page 2">1</a><a class="s-pagination--item js-pagination-item " href="/tags/gruntjs?p=2" rel="" title="Go to page 2">2</a><a class="s-pagination--item js-pagination-item " href="/tags/gruntjs?p=3" rel="" title="Go to page 2">3</a><a class="s-pagination--item js-pagination-item " href="/tags/gruntjs?p=4" rel="" title="Go to page 2">4</a><a class="s-pagination--item js-pagination-item " href="/tags/gruntjs?p=5" rel="" title="Go to page 2">5</a><a class="s-pagination--item js-pagination-item is-selected" href="/tags/gruntjs?p=6" rel="" title="Go to page 2">6</a><a class="s-pagination--item js-pagination-item " href="/tags/gruntjs?p=7" rel="" title="Go to page 2">7</a><a class="s-pagination--item js-pagination-item " href="/tags/gruntjs?p=8" rel="" title="Go to page 2">8</a><a class="s-pagination--item js-pagination-item " href="/tags/gruntjs?p=9" rel="" title="Go to page 2">9</a><a class="s-pagination--item js-pagination-item " href="/tags/gruntjs?p=10" rel="" title="Go to page 2">10</a></div> </div> <div id="sidebar" class="show-votes" role="complementary" aria-label="sidebar"> <div class="module js-gps-related-tags" id="related-tags"> <h4 id="h-related-tags">Reference</h4> <div data-name="javascript"> <a href="https://php.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">php</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">1429865</span> </span> </div> <div data-name="javascript"> <a href="https://c-cpp.com" class="post-tag no-tag-menu js-gps-track" target="_blank">c/c++</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">756500</span> </span> </div> <div data-name="javascript"> <a href="https://nginx.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">nginx</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">49975</span> </span> </div> <div data-name="javascript"> <a href="https://mongodb.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">mongodb</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">159057</span> </span> </div> <div data-name="javascript"> <a href="https://mybatis.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">mybatis</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">3233</span> </span> </div> <div data-name="javascript"> <a href="https://anaconda.org.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">anaconda</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">13410</span> </span> </div> <div data-name="javascript"> <a href="https://pycharm.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">pycharm</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">14671</span> </span> </div> <div data-name="javascript"> <a href="https://python.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">python</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">1902243</span> </span> </div> <div data-name="javascript"> <a href="https://vscode.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">vscode</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">56040</span> </span> </div> <div data-name="javascript"> <a href="https://dockerdocs.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">docker</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">110988</span> </span> </div> <div data-name="javascript"> <a href="https://github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">github</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">49000</span> </span> </div> <div data-name="javascript"> <a href="https://flask.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">flask</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">49129</span> </span> </div> <div data-name="javascript"> <a href="https://ffmpeg.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">ffmpeg</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">24037</span> </span> </div> <div data-name="javascript"> <a href="https://jmeter.net" class="post-tag no-tag-menu js-gps-track" target="_blank">jmeter</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">16910</span> </span> </div> <div data-name="javascript"> <a href="https://matplotlib.net" class="post-tag no-tag-menu js-gps-track" target="_blank">matplotlib</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">63493</span> </span> </div> <div data-name="javascript"> <a href="https://getbootstrap.net" class="post-tag no-tag-menu js-gps-track" target="_blank">bootstrap</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">54641</span> </span> </div> </div> </div> </div> </div> <footer id="footer" class="site-footer js-footer" role="contentinfo"> <div class="site-footer--container"> <div class="site-footer--logo"> <a href="https://stackoverflow.com"><svg aria-hidden="true" class="native svg-icon iconLogoGlyphMd" width="32" height="37" viewBox="0 0 32 37"><path d="M26 33v-9h4v13H0V24h4v9h22Z" fill="#BCBBBB"/><path d="m21.5 0-2.7 2 9.9 13.3 2.7-2L21.5 0ZM26 18.4 13.3 7.8l2.1-2.5 12.7 10.6-2.1 2.5ZM9.1 15.2l15 7 1.4-3-15-7-1.4 3Zm14 10.79.68-2.95-16.1-3.35L7 23l16.1 2.99ZM23 30H7v-3h16v3Z" fill="#F48024"/></svg></a> </div> <nav class="site-footer--nav"> <div class="site-footer--col"> <h5 class="-title"><a href="https://stackoverflow.org.cn" class="js-gps-track" data-gps-track="footer.click({ location: 3, link: 15})">Stack Overflow 中文网</a></h5> <p>遵从 CC BY-SA 知识共享许可协议。</p> </div> </nav> </div> </footer> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?709ff2ad9744e86b5b0eee677fc13ede"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-1MW5BV8G8E"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-1MW5BV8G8E'); </script> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6117966252207595" crossorigin="anonymous"></script> </body> </html>