Grunt: including a generated file in usemin

夙愿已清 提交于 2019-12-24 14:42:32

问题


This is the relevant part in my index.html:

<!-- build:js scripts/scripts.js -->
<script src="scripts/vendor/jquery.js"></script>
<script src="scripts/vendor/bootstrap.min.js"></script>
<script src="scripts/vendor/handlebars.runtime.js"></script>
<script src="scripts/vendor/ember.js"></script>
<script src="scripts/vendor/ember-data.js"></script>
<script src="scripts/templates.js"></script>
<script src="scripts/neuterapp.js"></script>
<!-- endbuild -->

(but the last two entrires are wrong, that is actually my problem)

This is the relevant part of the Gruntfile.js:

    useminPrepare: {
        html: '<%= yeoman.app %>/index.html',
        options: {
            dest: '<%= yeoman.dist %>'
        }
    },
    usemin: {
        html: ['<%= yeoman.dist %>/*.html'],
        css: ['<%= yeoman.dist %>/styles/*.css'],
        options: {
            dirs: ['<%= yeoman.dist %>']
        }
    },

The problem that I have is that both templates.js and neuterapp.js are generated files, so they are not in <%= yeoman.app %>/scripts, but in <%= yeoman.dist %>/scripts.

This is my (simplified) directory structure:

webapp/
├── app
│   ├── app.js <--- for neuter
│   ├── controllers
│   ├── index.html
│   ├── models
│   ├── routes
│   ├── scripts
│   │   └── vendor <--- for usemin
│   ├── templates <--- for ember_templates
│   │   ├── template1.hbs
│   │   └── template2.hbs
│   └── views
├── dist
│   ├── index.html
│   └── scripts
│       ├── neuterapp.js <--- this must also be used for usemin!!!
│       └── templates.js <--- this must also be used for usemin!!!
└── Gruntfile.js

How can I tell usemin to include some generated files?

And in case this is needed, these are the configurations of neuter and ember_templates:

    neuter: {
        options: {
            includeSourceURL: true
        },
        '<%= yeoman.dist %>/scripts/neuterapp.js': '<%= yeoman.app %>/app.js'
    },
    ember_templates: {
        compile: {
            options: {
                templateName: function (sourceFile) {
                    return sourceFile.replace(/app\/templates\//, ''); // <%= yeoman.dist %>/scripts/
                }
            },
            files: {
                '<%= yeoman.dist %>/scripts/templates.js': [
                    '<%= yeoman.app %>/templates/**/*.hbs'
                ]
            }
        }
    },

回答1:


You might use the copy task to prepare what usemin needs in a temporary location.

What I suggest you do:

  • copy your needed app files from app to temp
  • Let your tasks which generate files output to temp
  • let your usemin & useminPrepare task run on temp and output to dist.


来源:https://stackoverflow.com/questions/15922554/grunt-including-a-generated-file-in-usemin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!