[英]Setting a target or multiplefile for a grunt task with sass and autoprefixer?
I'm setting a grunt file for a task. 我正在为任务设置文件。 My goal is to create a css file from a sass file (scss) and add an autoprefix to all the proprieties which require so.
我的目标是从一个sass文件(scss)创建一个css文件,并向需要的所有属性添加自动前缀。 Initially I used the propriety multifiles but it didn't work, so now I'm using the target propriety that works fine, but my problem is, even if I target the very same file, it will create another file in my folder where I put all my sass files.
最初,我使用了适当的多文件,但是它没有用,所以现在我使用的是正常的目标适当,但是我的问题是,即使我以相同的文件为目标,它也会在我所在的文件夹中创建另一个文件把我所有的sass文件。
So far my file is the following: 到目前为止,我的文件如下:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dev: {
options: {
style: 'expanded',
sourcemap: 'none',
},
files: {
'../style.css': 'scss/style.scss'
}
},
dist: {
options: {
style: 'compressed',
sourcemap: 'none',
},
files: {
'../style-min.css': 'scss/style.scss'
}
}
},
autoprefixer: {
options: {
browsers: ['last 6 versions']
},
target: {
expand: true,
flatten: true,
src: '../style.css',
dest: ''
}
},
watch: {
css: {
files: '**/*.scss',
tasks: ['sass', 'autoprefixer']
}
},
});
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.registerTask('default', ['watch']);
}
My goal is to set up a global task for all my css files, like so: 我的目标是为我的所有CSS文件设置全局任务,如下所示:
target: {
expand: true,
flatten: true,
src: '*.css',
dest: ''
}
but it is not working even if I try something like: 但是即使我尝试类似的方法也无法正常工作:
target: {
expand: true,
flatten: true,
src: '../*.css',
dest: ''
}
Does anyone know why? 有人知道为什么吗?
Use cwd
(stands for current working directory) which is the path where grunt looks for the files matching the pattern in src
. 使用
cwd
(代表当前工作目录),这是grunt在src
查找与模式匹配的文件的路径。 Also define the dest
so that it would create the destination file in the same folder. 还定义
dest
以便它将在同一文件夹中创建目标文件。
target: {
expand: true,
flatten: true,
cwd: '../',
src: [ '**/*.css' ],
dest: '../'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.