我在 Angular JS 项目中处理我的 Gruntfile。
在这一步中,我将所有 html 模板转换为 Angular 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'
} },
我已将目标文件夹设置为“.tmp”
然后我使用“usemin”
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.
}
},
我注册了我的任务:
grunt.registerTask('build', [
'clean:dist',
'html2js:app',
'useminPrepare',
'concat:generated',
'cssmin:generated',
'uglify:generated',
'usemin',
'copy:dist',
'htmlmin:dist',
// 'clean:tmp'
]);
如何添加模板文件以供 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'
]);
};