Note: This question is only relevant for Grunt 0.3.x and has been left for reference. For help with the latest Grunt 1.x release please see my comment below this question.个
我正在try 使用Grunt.js设置一个自动构建过程,首先连接然后缩小CSS和JavaScript文件.
我已经能够成功地连接和缩小我的JavaScript文件,尽管每次我运行Grut时,它似乎只是追加到文件中,而不是覆盖它们.
至于缩小甚至拼接CSS,我到目前为止还无法做到这一点!
在grunt CSS模块方面,我try 使用consolidate-css
、grunt-css
和;cssmin
但没有用.我不知道如何使用它们!
我的目录 struct 如下(作为一个典型的node.js应用程序):
- app.js
- grunt.js
- /public/index.html
- /public/css/[各种css文件]
- /public/js/[各种javascript文件]
下面是我的grunt.js文件在我的应用程序根文件夹中的当前外观:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: '<json:package.json>',
concat: {
dist: {
src: 'public/js/*.js',
dest: 'public/js/concat.js'
}
},
min: {
dist: {
src: 'public/js/concat.js',
dest: 'public/js/concat.min.js'
}
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
node: true
},
globals: {
exports: true,
module: false
}
},
uglify: {}
});
// Default task.
grunt.registerTask('default', 'concat min');
};
总而言之,我需要两个问题的帮助:
- 如何将我在文件夹
/public/css/
下的所有CSS文件连接并缩小为一个文件,比如说main.min.css
- 为什么grunt.js一直附加到
/public/js/
下连接和缩小的javascript文件concat.js
和concat.min.js
,而不是在每次运行命令grunt
时覆盖它们?
Updated 5th of July 2016 - Upgrading from Grunt 0.3.x to Grunt 0.4.x or 1.x个
Grunt.js
已移动到Grunt 0.4.x
中的新 struct (该文件现在称为Gruntfile.js
).请参阅我的开放源码项目Grunt.js Skeleton以获取有关为Grunt 1.x
设置构建过程的帮助.
从Grunt 0.4.x
上升到Grunt 1.x
should not introduce many major changes.