【问题标题】:Grunt-include-source + usemin don't work togetherGrunt-include-source + usemin 不能一起工作
【发布时间】:2014-09-13 13:59:42
【问题描述】:

我正在关注这个 SO 答案 How to include scripts automatically in a yeoman/grunt project? 如何通过 usemin 插件包含脚本文件夹中的所有 js 文件。添加 grunt-include-source 插件后,usemin 无法将生成的脚本块替换为正确的 concated+minified 脚本,该块仅被删除或仅填充源标签。

index.html中的源码是这样的:

<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
<!-- endbower -->
<!-- endbuild -->

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<!-- include: "type": "js", "files": "scripts/**/*.js" -->
<!-- endbuild -->

在 grunt-include-source 和 grunt-wiredep 之后是这样的代码:

<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/es5-shim/es5-shim.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/json3/lib/json3.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<!-- endbower -->
<!-- endbuild -->

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/about.js"></script>
<script src="scripts/controllers/company/list.js"></script>
<script src="scripts/controllers/dashboard/main.js"></script>
... more ...
<!-- endbuild -->

我正在使用 grunt-wiredep 插件,它在 grunt-include-source 之后和 grunt-usemin 之前运行,此代码被正确替换。

输出应该是:

<script src="scripts/vendor.1e81ad0a.js"></script>
<script src="scripts/scripts.1e82ad0a.js"></script>

但只是:

<script src="scripts/vendor.1e81ad0a.js"></script>

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/about.js"></script>
<script src="scripts/controllers/company/list.js"></script>
<script src="scripts/controllers/dashboard/main.js"></script>
... more ...
<!-- endbuild -->

有人有解决这个问题的办法吗?

提前致谢, 迈克尔

【问题讨论】:

  • 我找到了解决此问题的方法。我拒绝使用 grunt-include-source 插件并将其替换为grunt-file-blocks。这与 grunt-usemin 完美搭配。

标签: gruntjs grunt-usemin


【解决方案1】:

在任务中:'copy:dist' 注释 html 的副本,这样好的 index.html(在 includesource 运行后)不会再次被应用程序中的 index.html 覆盖

copy: {
      dist: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= yeoman.app %>',
          dest: '<%= yeoman.dist %>',
          src: [
            '*.{ico,png,txt}',
            '.htaccess',
            //'*.html',
            'views/{,*/}*.html',
            'images/{,*/}*.{webp}',
            'fonts/*'
          ]
        }

【讨论】:

  • 我只想在这里添加一些信息,因为没有上下文我不清楚。如果您查看此答案 stackoverflow.com/questions/21232889/… 包含源配置有一个 dist 属性,该属性指示插件包含从 app/index.html 到 dist/index.html 的源。所以你已经将 index.html 复制到了 dist。
猜你喜欢
  • 2017-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-28
  • 2018-11-27
  • 2012-11-04
  • 2013-12-29
相关资源
最近更新 更多