Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gruntjs 如何添加另一个生成的javascript文件以供usemin grunt进程提取?_Gruntjs_Grunt Usemin - Fatal编程技术网

Gruntjs 如何添加另一个生成的javascript文件以供usemin grunt进程提取?

Gruntjs 如何添加另一个生成的javascript文件以供usemin grunt进程提取?,gruntjs,grunt-usemin,Gruntjs,Grunt Usemin,我在一个有棱角的JS项目中与Grunfile进行斗争 在这一步中,我将所有html模板转换为角度js组件: html2js: { app: { options: { htmlmin: { collapseBooleanAttributes: true, collapseWhitespace: true,

我在一个有棱角的JS项目中与Grunfile进行斗争

在这一步中,我将所有html模板转换为角度js组件:

html2js: {
            app: {
                options: {
                    htmlmin: {
                        collapseBooleanAttributes: true,
                        collapseWhitespace: true,
                        removeAttributeQuotes: true,
                        removeComments: true,
                        removeEmptyAttributes: true,
                        removeRedundantAttributes: true,
                        removeScriptTypeAttributes: true,
                        removeStyleLinkTypeAttributes: true
                    }
                },
                src: [ '<%= settings.app %>/app/**/*.tpl.html' ],
                dest: '.tmp/concat/js/templates-app.js'
如何添加模板文件以供useminprepare使用?有什么想法吗?

这是我所有的文件:

module.exports = function(grunt) {

    // Load grunt tasks automatically.
    require('load-grunt-tasks')(grunt);

    // Configurable paths for the application.
    var appConfig = {
        app: require('./bower.json').appPath || 'src',
        dist: 'dist'
    };

    grunt.initConfig({

        settings: appConfig,

        clean: {
            dist: {
                files: [{
                    dot: true,
                    src: [
                        '.tmp',
                        '<%= settings.dist %>/{,*/}*',
                        '!<%= settings.dist %>/.git*'
                    ]
                }]
            },
            tmp: {
                src: '.tmp'
            }
        },

        html2js: {
            app: {
                options: {
                    htmlmin: {
                        collapseBooleanAttributes: true,
                        collapseWhitespace: true,
                        removeAttributeQuotes: true,
                        removeComments: true,
                        removeEmptyAttributes: true,
                        removeRedundantAttributes: true,
                        removeScriptTypeAttributes: true,
                        removeStyleLinkTypeAttributes: true
                    }
                },
                src: [ '<%= settings.app %>/app/**/*.tpl.html' ],
                dest: '.tmp/concat/js/templates-app.js'
            }
        },

        useminPrepare: {
            html: '<%= settings.app %>/index.html',
            options: {
                // This is the folder which holds our build.
                dest: '<%= settings.dist %>',
                // This is the temp folder, which is used by "usemin", to prepare the build.
                // It needs to be cleaned when finished.
            }
        },

        usemin: {
            html: '<%= settings.dist %>/index.html'
        },

        concat: {
            environment: {
                src: ['.tmp/concat/js/app.js', '.tmp/concat/js/templates-app.js'],
                dest: '.tmp/concat/js/app.js'
            }
        },

        copy: {
            dist: {
                files: [
                    { 
                        src: '<%= settings.app %>/index.html', 
                        dest: '<%= settings.dist %>/index.html'
                    },{
                        expand: true,
                        cwd: '<%= settings.app %>/assets',
                        src: ['**'],
                        dest: '<%= settings.dist %>/assets'
                    },{
                        // Set working folder - root to copy.
                        // cwd: '<%= settings.app %>/app', 
                        // Copy all template files and subfolders.
                        // src: '**/*.tpl.html', 
                        // Destination folder.
                        // dest: '<%= settings.dist %>/app',
                        // Required when using cwd.
                        // expand: true
                    }
                ]
            }
        },

        // Minifies everything after they have been copied.
        htmlmin: {
            dist: {
                options: {
                    collapseWhitespace: true,
                    conservativeCollapse: false,
                    collapseBooleanAttributes: true,
                    removeCommentsFromCDATA: true,
                    removeOptionalTags: true
                },
                files: [{
                    expand: true,
                    cwd: '<%= settings.dist %>',
                    src: ['*.html', '**/*.tpl.html'],
                    dest: '<%= settings.dist %>'
                }]
            }
        },

        /**
         * karma
         */

        karma: {
            unit: {
                configFile: 'karma/karma.conf.js'
            }
        }
    });

    grunt.registerTask('build', [
        'clean:dist',
        'html2js:app',
        'useminPrepare',
        'concat:generated',
        'cssmin:generated',
        'uglify:generated',
        'usemin',
        'copy:dist',
        'htmlmin:dist',
        // 'clean:tmp'
    ]);

    grunt.registerTask('test', [
        'karma:unit'
    ]);
};
module.exports=函数(grunt){
//自动加载grunt任务。
要求('load-grunt-tasks')(grunt);
//应用程序的可配置路径。
var appConfig={
app:require('./bower.json').appPath | |'src',
dist:“dist”
};
grunt.initConfig({
设置:appConfig,
清洁:{
地区:{
档案:[{
多特:没错,
src:[
“.tmp”,
'/{,*/}*',
“!/.git*”
]
}]
},
tmp:{
src:“.tmp”
}
},
html2js:{
应用程序:{
选项:{
htmlmin:{
collapseBooleanAttributes:没错,
拼贴空白:对,
RemoveAttribute属性:对,
removeComments:对,
RemovemptyAttributes:没错,
删除和声明:是的,
removeScriptTypeAttributes:true,
removeStyleLinkTypeAttributes:true
}
},
src:['/app/***.tpl.html'],
dest:“.tmp/concat/js/templates app.js”
}
},
使用准备:{
html:“/index.html”,
选项:{
//这是保存我们的构建的文件夹。
目标:'',
//这是临时文件夹,“usemin”使用它来准备构建。
//完工后需要清洗。
}
},
usemin:{
html:“/index.html”
},
康卡特:{
环境:{
src:['.tmp/concat/js/app.js','.tmp/concat/js/templates-app.js'],
目标:'.tmp/concat/js/app.js'
}
},
副本:{
地区:{
档案:[
{ 
src:“/index.html”,
dest:“/index.html”
},{
是的,
cwd:“/资产”,
src:['**'],
目标:“/资产”
},{
//将工作文件夹-root设置为复制。
//cwd:“/app”,
//复制所有模板文件和子文件夹。
//src:“***.tpl.html”,
//目标文件夹。
//目标:'/app',
//使用cwd时需要。
//扩展:正确
}
]
}
},
//复制后缩小所有内容。
htmlmin:{
地区:{
选项:{
拼贴空白:对,
保守派:错,
collapseBooleanAttributes:没错,
removeCommentsFromCDATA:true,
removeOptionalTags:true
},
档案:[{
是的,
cwd:“”,
src:['*.html','**.tpl.html'],
目标:“”
}]
}
},
/**
*业力
*/
业力:{
单位:{
configFile:'karma/karma.conf.js'
}
}
});
grunt.registerTask('build'[
“清洁区”,
“html2js:app”,
“使用MinPrepare”,
“concat:已生成”,
“cssmin:已生成”,
'丑陋:已生成',
“usemin”,
'副本:dist',
'htmlmin:dist',
//“清洁:tmp”
]);
grunt.registerTask('test'[
‘因果报应:单位’
]);
};

我和你在同一个问题上苦苦挣扎(我当时喝得酩酊大醉,但概念相同)

我成功地将一个空的templates.js文件添加到index.html文件中,在运行use min之前,我使用
grunt/gulp angular templates
将模板放入templates.js文件中。这样,当use-min运行时,它已经有了对模板文件的引用,并成功地将模板连接到js的其余部分

grunt.registerTask('build', [
        'clean:dist',
        'html2js:app',
        'useminPrepare',
        'concat:generated',
        'cssmin:generated',
        'uglify:generated',
        'usemin',
        'copy:dist',
        'htmlmin:dist',
        // 'clean:tmp'
    ]);
module.exports = function(grunt) {

    // Load grunt tasks automatically.
    require('load-grunt-tasks')(grunt);

    // Configurable paths for the application.
    var appConfig = {
        app: require('./bower.json').appPath || 'src',
        dist: 'dist'
    };

    grunt.initConfig({

        settings: appConfig,

        clean: {
            dist: {
                files: [{
                    dot: true,
                    src: [
                        '.tmp',
                        '<%= settings.dist %>/{,*/}*',
                        '!<%= settings.dist %>/.git*'
                    ]
                }]
            },
            tmp: {
                src: '.tmp'
            }
        },

        html2js: {
            app: {
                options: {
                    htmlmin: {
                        collapseBooleanAttributes: true,
                        collapseWhitespace: true,
                        removeAttributeQuotes: true,
                        removeComments: true,
                        removeEmptyAttributes: true,
                        removeRedundantAttributes: true,
                        removeScriptTypeAttributes: true,
                        removeStyleLinkTypeAttributes: true
                    }
                },
                src: [ '<%= settings.app %>/app/**/*.tpl.html' ],
                dest: '.tmp/concat/js/templates-app.js'
            }
        },

        useminPrepare: {
            html: '<%= settings.app %>/index.html',
            options: {
                // This is the folder which holds our build.
                dest: '<%= settings.dist %>',
                // This is the temp folder, which is used by "usemin", to prepare the build.
                // It needs to be cleaned when finished.
            }
        },

        usemin: {
            html: '<%= settings.dist %>/index.html'
        },

        concat: {
            environment: {
                src: ['.tmp/concat/js/app.js', '.tmp/concat/js/templates-app.js'],
                dest: '.tmp/concat/js/app.js'
            }
        },

        copy: {
            dist: {
                files: [
                    { 
                        src: '<%= settings.app %>/index.html', 
                        dest: '<%= settings.dist %>/index.html'
                    },{
                        expand: true,
                        cwd: '<%= settings.app %>/assets',
                        src: ['**'],
                        dest: '<%= settings.dist %>/assets'
                    },{
                        // Set working folder - root to copy.
                        // cwd: '<%= settings.app %>/app', 
                        // Copy all template files and subfolders.
                        // src: '**/*.tpl.html', 
                        // Destination folder.
                        // dest: '<%= settings.dist %>/app',
                        // Required when using cwd.
                        // expand: true
                    }
                ]
            }
        },

        // Minifies everything after they have been copied.
        htmlmin: {
            dist: {
                options: {
                    collapseWhitespace: true,
                    conservativeCollapse: false,
                    collapseBooleanAttributes: true,
                    removeCommentsFromCDATA: true,
                    removeOptionalTags: true
                },
                files: [{
                    expand: true,
                    cwd: '<%= settings.dist %>',
                    src: ['*.html', '**/*.tpl.html'],
                    dest: '<%= settings.dist %>'
                }]
            }
        },

        /**
         * karma
         */

        karma: {
            unit: {
                configFile: 'karma/karma.conf.js'
            }
        }
    });

    grunt.registerTask('build', [
        'clean:dist',
        'html2js:app',
        'useminPrepare',
        'concat:generated',
        'cssmin:generated',
        'uglify:generated',
        'usemin',
        'copy:dist',
        'htmlmin:dist',
        // 'clean:tmp'
    ]);

    grunt.registerTask('test', [
        'karma:unit'
    ]);
};