Grunt less 不会替换 css 文件
Grunt less won't replace css file
我使用 grunt-contrib-less 和 grunt-contrib-watch 来在更改时自动编译我的 less 文件。
当 css 不存在时,grunt 可以编译它。当 css 已经存在并且 watch 看到 less 文件被更改时,css 文件没有被修改。我每次都必须删除它,然后让 grunt 用修改重新创建它。
少配置:
less: {
options: {
banner: '<%= meta.banner %>'
},
dev: {
options: {
sourceMap: true,
sourceMapFileInline: true,
compress: true
},
src: '<%= meta.dev.less %>/main.less',
dest: '<%= meta.prod.css %>/main.css'
},
prod: {
options: {
plugins: [
new( require( 'less-plugin-clean-css' ) )( {
'advanced': true,
'compatibility': 'ie9'
} )
],
},
src: '<%= meta.dev.less %>/main.less',
dest: '<%= meta.prod.css %>/main.css'
}
},
我在 Windows 10 岁以下,每个用户都有权 modifiy/delete 我的 dist 文件夹中的文件。
如何让 grunt 修改 css 文件?
编辑
观看配置
watch: {
options: {
livereload: 6325
},
js: {
files: [ '<%= meta.dev.js %>/main.js', '<%= meta.dev.js %>/plugins/*.js' ],
tasks: [ 'newer:concat' ]
},
images: {
files: '<%= meta.dev.img %>/**/*.{png,jpg,gif,svg}',
tasks: [ 'newer:imagemin' ]
},
css: {
files: '<%= meta.dev.less %>/**/*.less',
tasks: [ 'newer:less:dev' ]
}
}
注册
grunt.registerTask( 'default', [ 'less:dev', 'concat', 'imagemin', 'copy', 'watch' ] );
Grunt 输出(详细)
>> File "dev\less\elements\menu.less" changed.
Initializing
Command-line options: --verbose
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ default, prod
Running tasks: newer:less:dev
Loading "grunt-newer" plugin
Registering "D:\[...]\static\node_modules\grunt-newer\tasks" tasks.
Loading "newer.js" tasks...OK
+ any-newer, newer, newer-clean, newer-postrun
Running "newer:less:dev" (newer) task
Options: cache="D:\[...]\static\node_modules\grunt-newer\.cache", override=undefined
Files: dev/less/main.less -> dist/css/main.css
No newer files to process.
您是否以更少的价格添加了正确的手表配置?
watch: {
less: {
files: ['less/**/*.less'], // which files to watch
tasks: ['less'],
options: {
nospawn: true
}
}
}
到 运行 g运行t 与您的个人资料:grunt.registerTask('myprofile', ['less:dev', 'watch']);
事情是这样的:
- 你修改
menu.less
- watch 检测到 运行s
newer:less:dev
less:dev
使用文件 main.less
作为唯一来源(不是 menu.less
)
- 该文件没有更改,因此
newer
得出结论它不需要再次 运行 任务
我想 main.less
包括 menu.less
,但 newer
不知道。
所以我建议的解决方法是去掉 newer
部分。
我使用 grunt-contrib-less 和 grunt-contrib-watch 来在更改时自动编译我的 less 文件。 当 css 不存在时,grunt 可以编译它。当 css 已经存在并且 watch 看到 less 文件被更改时,css 文件没有被修改。我每次都必须删除它,然后让 grunt 用修改重新创建它。
少配置:
less: {
options: {
banner: '<%= meta.banner %>'
},
dev: {
options: {
sourceMap: true,
sourceMapFileInline: true,
compress: true
},
src: '<%= meta.dev.less %>/main.less',
dest: '<%= meta.prod.css %>/main.css'
},
prod: {
options: {
plugins: [
new( require( 'less-plugin-clean-css' ) )( {
'advanced': true,
'compatibility': 'ie9'
} )
],
},
src: '<%= meta.dev.less %>/main.less',
dest: '<%= meta.prod.css %>/main.css'
}
},
我在 Windows 10 岁以下,每个用户都有权 modifiy/delete 我的 dist 文件夹中的文件。 如何让 grunt 修改 css 文件?
编辑
观看配置
watch: {
options: {
livereload: 6325
},
js: {
files: [ '<%= meta.dev.js %>/main.js', '<%= meta.dev.js %>/plugins/*.js' ],
tasks: [ 'newer:concat' ]
},
images: {
files: '<%= meta.dev.img %>/**/*.{png,jpg,gif,svg}',
tasks: [ 'newer:imagemin' ]
},
css: {
files: '<%= meta.dev.less %>/**/*.less',
tasks: [ 'newer:less:dev' ]
}
}
注册
grunt.registerTask( 'default', [ 'less:dev', 'concat', 'imagemin', 'copy', 'watch' ] );
Grunt 输出(详细)
>> File "dev\less\elements\menu.less" changed.
Initializing
Command-line options: --verbose
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ default, prod
Running tasks: newer:less:dev
Loading "grunt-newer" plugin
Registering "D:\[...]\static\node_modules\grunt-newer\tasks" tasks.
Loading "newer.js" tasks...OK
+ any-newer, newer, newer-clean, newer-postrun
Running "newer:less:dev" (newer) task
Options: cache="D:\[...]\static\node_modules\grunt-newer\.cache", override=undefined
Files: dev/less/main.less -> dist/css/main.css
No newer files to process.
您是否以更少的价格添加了正确的手表配置?
watch: {
less: {
files: ['less/**/*.less'], // which files to watch
tasks: ['less'],
options: {
nospawn: true
}
}
}
到 运行 g运行t 与您的个人资料:grunt.registerTask('myprofile', ['less:dev', 'watch']);
事情是这样的:
- 你修改
menu.less
- watch 检测到 运行s
newer:less:dev
less:dev
使用文件main.less
作为唯一来源(不是menu.less
)- 该文件没有更改,因此
newer
得出结论它不需要再次 运行 任务
我想 main.less
包括 menu.less
,但 newer
不知道。
所以我建议的解决方法是去掉 newer
部分。