Gruntjs grunt cssmin保留非精简版本
我正在使用yeoman 1.0 rc和grunt创建一个静态网站,一切都很好,但我想做的除了css缩小版,一个所有文件路径都更新的非缩小版,这是可行的,我如何才能做到这一点 GrunFile是由yo webapp创建的一个非常标准的grunt文件Gruntjs grunt cssmin保留非精简版本,gruntjs,yeoman,Gruntjs,Yeoman,我正在使用yeoman 1.0 rc和grunt创建一个静态网站,一切都很好,但我想做的除了css缩小版,一个所有文件路径都更新的非缩小版,这是可行的,我如何才能做到这一点 GrunFile是由yo webapp创建的一个非常标准的grunt文件 module.exports = function (grunt) { // load all grunt tasks require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTask
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// configurable paths
var yeomanConfig = {
app: 'app',
dist: 'dist'
};
grunt.initConfig({
yeoman: yeomanConfig,
watch: {
options: {
nospawn: true
},
coffee: {
files: ['<%= yeoman.app %>/scripts/{,*/}*.coffee'],
tasks: ['coffee:dist']
},
coffeeTest: {
files: ['test/spec/{,*/}*.coffee'],
tasks: ['coffee:test']
},
compass: {
files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
tasks: ['compass:server']
},
livereload: {
options: {
livereload: LIVERELOAD_PORT
},
files: [
'<%= yeoman.app %>/*.html',
'{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
'{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
connect: {
options: {
port: 9000,
// change this to '0.0.0.0' to access the server from outside
hostname: 'localhost'
},
livereload: {
options: {
middleware: function (connect) {
return [
mountFolder(connect, '.tmp'),
mountFolder(connect, yeomanConfig.app),
lrSnippet
];
}
}
},
test: {
options: {
middleware: function (connect) {
return [
mountFolder(connect, '.tmp'),
mountFolder(connect, 'test')
];
}
}
},
dist: {
options: {
middleware: function (connect) {
return [
mountFolder(connect, yeomanConfig.dist)
];
}
}
}
},
open: {
server: {
path: 'http://localhost:<%= connect.options.port %>'
}
},
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>/*',
'!<%= yeoman.dist %>/.git*'
]
}]
},
server: '.tmp'
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= yeoman.app %>/scripts/{,*/}*.js',
'!<%= yeoman.app %>/scripts/vendor/*',
'test/spec/{,*/}*.js'
]
},
mocha: {
all: {
options: {
run: true,
urls: ['http://localhost:<%= connect.options.port %>/index.html']
}
}
},
coffee: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/scripts',
src: '{,*/}*.coffee',
dest: '.tmp/scripts',
ext: '.js'
}]
},
test: {
files: [{
expand: true,
cwd: 'test/spec',
src: '{,*/}*.coffee',
dest: '.tmp/spec',
ext: '.js'
}]
}
},
compass: {
options: {
sassDir: '<%= yeoman.app %>/styles',
cssDir: '.tmp/styles',
generatedImagesDir: '.tmp/images/generated',
imagesDir: '<%= yeoman.app %>/images',
javascriptsDir: '<%= yeoman.app %>/scripts',
fontsDir: '<%= yeoman.app %>/styles/fonts',
importPath: '<%= yeoman.app %>/bower_components',
httpImagesPath: '/images',
httpGeneratedImagesPath: '/images/generated',
relativeAssets: false
},
dist: {
options:{
outputStyle: 'nested'
}
},
server: {
options: {
debugInfo: true
}
}
},
// not used since Uglify task does concat,
// but still available if needed
/*concat: {
dist: {}
},*/
// not enabled since usemin task does concat and uglify
// check index.html to edit your build targets
// enable this task if you prefer defining your build targets here
/*uglify: {
dist: {}
},*/
rev: {
dist: {
files: {
src: [
'<%= yeoman.dist %>/scripts/{,*/}*.js',
'<%= yeoman.dist %>/styles/{,*/}*.css',
'<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}',
'<%= yeoman.dist %>/styles/fonts/*'
]
}
}
},
useminPrepare: {
options: {
dest: '<%= yeoman.dist %>'
},
html: '<%= yeoman.app %>/index.html'
},
usemin: {
options: {
dirs: ['<%= yeoman.dist %>']
},
html: ['<%= yeoman.dist %>/{,*/}*.html'],
css: ['<%= yeoman.dist %>/styles/{,*/}*.css']
},
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.{png,jpg,jpeg}',
dest: '<%= yeoman.dist %>/images'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.svg',
dest: '<%= yeoman.dist %>/images'
}]
}
},
cssmin: {
dist: {
files: {
'<%= yeoman.dist %>/styles/main.css': [
'.tmp/styles/{,*/}*.css',
'<%= yeoman.app %>/styles/{,*/}*.css'
]
}
}
},
htmlmin: {
dist: {
options: {
/*removeCommentsFromCDATA: true,
// https://github.com/yeoman/grunt-usemin/issues/44
//collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeOptionalTags: true*/
},
files: [{
expand: true,
cwd: '<%= yeoman.app %>',
src: '*.html',
dest: '<%= yeoman.dist %>'
}]
}
},
// Put files not handled in other tasks here
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,txt}',
'.htaccess',
'images/{,*/}*.{webp,gif}',
'styles/fonts/*'
]
}, {
expand: true,
cwd: '.tmp/images',
dest: '<%= yeoman.dist %>/images',
src: [
'generated/*'
]
}]
}
},
concurrent: {
server: [
'coffee:dist',
'compass:server'
],
test: [
'coffee',
'compass'
],
dist: [
'coffee',
'compass:dist',
'imagemin',
'svgmin',
'htmlmin'
]
}
});
grunt.registerTask('server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'open', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'concurrent:server',
'connect:livereload',
'open',
'watch'
]);
});
grunt.registerTask('test', [
'clean:server',
'concurrent:test',
'connect:test',
'mocha'
]);
grunt.registerTask('build', [
'clean:dist',
'useminPrepare',
'concurrent:dist',
'cssmin',
'concat',
'uglify',
'copy',
'rev',
'usemin'
]);
grunt.registerTask('default', [
'jshint',
'test',
'build'
]);
module.exports=函数(grunt){
//加载所有grunt任务
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
//可配置路径
var yeomanConfig={
应用程序:“应用程序”,
dist:“dist”
};
grunt.initConfig({
约曼:约曼图,
观察:{
选项:{
nospawn:是的
},
咖啡:{
文件:['/scripts/{,*/}*.coffee'],
任务:['coffee:dist']
},
咖啡测试:{
文件:['test/spec/{,*/}*.coffee'],
任务:[“咖啡:测试”]
},
指南针:{
文件:['/styles/{,*/}*{scss,sass}'],
任务:['compass:server']
},
利弗雷罗德:{
选项:{
利弗雷洛德:利弗雷洛德港口
},
档案:[
“/*.html”,
“{.tmp,}/styles/{,*/}*.css”,
“{.tmp,}/scripts/{,*/}*.js”,
“/images/{,*/}*{png,jpg,jpeg,gif,webp,svg}”
]
}
},
连接:{
选项:{
港口:9000,
//将此更改为“0.0.0.0”以从外部访问服务器
主机名:“localhost”
},
利弗雷罗德:{
选项:{
中间件:功能(连接){
返回[
mountFolder(连接“.tmp”),
mountFolder(连接,yeomanConfig.app),
LRS片段
];
}
}
},
测试:{
选项:{
中间件:功能(连接){
返回[
mountFolder(连接“.tmp”),
安装文件夹(连接“测试”)
];
}
}
},
地区:{
选项:{
中间件:功能(连接){
返回[
mountFolder(连接,yeomanConfig.dist)
];
}
}
}
},
开放式:{
服务器:{
路径:'http://localhost:'
}
},
清洁:{
地区:{
档案:[{
多特:没错,
src:[
“.tmp”,
'/*',
“!/.git*”
]
}]
},
服务器:'.tmp'
},
jshint:{
选项:{
jshintrc:“.jshintrc”
},
全部:[
“Gruntfile.js”,
“/scripts/{,*/}*.js”,
“!/scripts/vendor/*”,
'test/spec/{,*/}*.js'
]
},
摩卡咖啡:{
全部:{
选项:{
run:是的,
网址:['http://localhost:/index.html']
}
}
},
咖啡:{
地区:{
档案:[{
是的,
cwd:“/scripts”,
src:“{,*/}*.coffee”,
目标:'.tmp/scripts',
分机:'.js'
}]
},
测试:{
档案:[{
是的,
cwd:“测试/规范”,
src:“{,*/}*.coffee”,
目的地:'.tmp/spec',
分机:'.js'
}]
}
},
指南针:{
选项:{
sassDir:“/styles”,
cssDir:“.tmp/styles”,
generatedImagesDir:'.tmp/images/generated',
imagesDir:“/images”,
javascriptsDir:“/scripts”,
fontsDir:“/styles/fonts”,
导入路径:'/bower_components',
httpImagesPath:“/images”,
httpGeneratedImagesPath:“/images/generated”,
相对论集:假
},
地区:{
选项:{
outputStyle:“嵌套”
}
},
服务器:{
选项:{
debugInfo:true
}
}
},
//未使用,因为丑陋的任务不起作用,
//但如果需要,仍然可用
/*康卡特:{
地区:{}
},*/
//未启用,因为usemin任务没有concat和uglify
//选中index.html以编辑生成目标
//如果希望在此处定义生成目标,请启用此任务
/*丑陋的:{
地区:{}
},*/
修订版:{
地区:{
档案:{
src:[
“/scripts/{,*/}*.js”,
“/styles/{,*/}*.css”,
“/images/{,*/}*{png,jpg,jpeg,gif,webp}”,
“/styles/fonts/*”
]
}
}
},
使用准备:{
选项:{
目标:“”
},
html:“/index.html”
},
usemin:{
选项:{
目录:['']
},
html:['/{,*/}*.html'],
css:['/styles/{,*/}*.css']
},
imagemin:{
地区:{
档案:[{
是的,
cwd:“/images”,
src:“{,*/}*{png,jpg,jpeg}”,
目标:'/images'
}]
}
},
斯维格明:{
地区:{
档案:[{
是的,
cwd:“/images”,
src:'{,*/}*.svg',,
目标:'/images'
}]
}
},
cssmin:{
地区:{
档案:{
“/styles/main.css”:[
“.tmp/styles/{,*/}*.css”,
“/styles/{,*/}*.css”
]
}
}
},
htmlmin:{
地区:{
选项:{
/*removeCommentsFromCDATA:true,