我正在努力让grunt-usemin与Sass一起工作。
这是我的文件夹树:
root
|-- source
| |-- index.html
| |-- scss
| |-- main.scss
|-- Gruntfile.js
|-- package.json
|-- node_modules
| |-- [required modules]
My Gruntfile如下所示:
module.exports = function(grunt) {
grunt.config.init({
sass: {
dist: {
options: {
'sourcemap': 'none'
},
files: {
'build/dist/assets/css/style.css': 'source/scss/main.scss'
}
}
},
useminPrepare: {
html: 'source/index.html',
options: {
dest: 'build/dist'
}
},
usemin: {
html: 'build/dist/index.html'
},
filerev: {
stylesheets: {
src: 'build/dist/assets/css/style.css'
}
},
copy: {
dist: {
src: 'source/index.html',
dest: 'build/dist/index.html'
}
}
});
grunt.registerTask('build', [
'sass:dist',
'copy:dist',
'useminPrepare',
'concat:generated',
'cssmin:generated',
// 'uglify:generated',
'filerev',
'usemin'
]);
require('load-grunt-tasks')(grunt);
}
sass:dist
任务正在将main.scss
编译为build/assets/css/style.css
,但由于某种原因usemin
无法使用此文件进行缩小。生成的配置如下所示:
concat:
{ generated:
{ files:
[ { dest: '.tmp/concat/assets/css/style.css',
src: [ 'source/css/style.css' ] } ] } }
uglify:
{}
cssmin:
{ generated:
{ files:
[ { dest: 'build/dist/assets/css/style.css',
src: [ '.tmp/concat/assets/css/style.css' ] } ] } }
还有一些更有意思的输出:
Running "concat:generated" (concat) task
Verifying property concat.generated exists in config...OK
Files: [no src] -> .tmp/concat/assets/css/style.css
Options: separator="\n", banner="", footer="", stripBanners=false, process=false, sourceMap=false, sourceMapName=undefined, sourceMapStyle="embed"
Writing .tmp/concat/assets/css/style.css...OK
File .tmp/concat/assets/css/style.css created.
Running "cssmin:generated" (cssmin) task
Verifying property cssmin.generated exists in config...OK
Files: .tmp/concat/assets/css/style.css -> build/dist/assets/css/style.css
Options: report="min"
Reading .tmp/concat/assets/css/style.css...OK
>> Destination not written because minified CSS was empty.
在检查之后看起来concat:generated
任务在source/css/style.css
中寻找CSS文件,但当然不存在 - 它被编译到build/dist/assets/css/style.css
,因此每个任务都失败了。
如何解决此问题 - 我需要做些什么才能使concat:generated
查看正确的文件路径?