[英]Can GruntJS remove the bower_components folder after copying files?
I am using Bower and GruntJS. 我正在使用Bower和GruntJS。 I thought that grunt-bowercopy would remove the
bower_components
folder when it is done but this is not happening. 我以为grunt-bowercopy完成后会删除
bower_components
文件夹,但这没有发生。
Can grunt-bowercopy remove the bower_components folder after copying the files to the locations I want? 将文件复制到所需位置后,grunt-bowercopy可以删除bower_components文件夹吗?
Here is my folder setup: 这是我的文件夹设置:
->Project
->Themes
->Theme
->assets
->scripts
->styles
->tools
->build
->bower_components
->bower.json
->gruntfile.js
->package.json
Here is how I am running grunt-bowercopy in my gruntfile.js 这是我在gruntfile.js中运行grunt-bowercopy的方式
module.exports = function (grunt) {
// Loads the necessary tasks for this Grunt file.
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
bowercopy: {
options: {
clear: true
},
js: {
options: {
destPrefix: '../../Themes/Theme/assets/'
},
//The key is the destination file. The value is the file from the bower_components folder
//The files will be added to a scripts folder at the location: ../../themes/3MTheme/assets/scripts
//The key is the name of the folder that is copied into the /assets folder.
src : 'scripts'
},
css: {
options: {
destPrefix: '../../Themes/Theme/assets/'
},
src: 'styles'
}
}
// Custom task, executed via the command "grunt bowercopy"
grunt.registerTask('bower', ['bowercopy']);
};
It doesn't seem as if grunt-bowercopy does this for you, but I've done something similar for clearing reports before running test commands. 似乎grunt-bowercopy不会为您执行此操作,但是我已经执行了类似的操作,以便在运行测试命令之前清除报告。
Just create your own custom task called something like cleanbowercopy which executes an rmdir on the directory you are cleaning. 只需创建一个名为cleanbowercopy之类的自定义任务,该任务就会在要清理的目录上执行rmdir 。
Then update your register task to call it after bowercopy: 然后更新您的注册任务以在bowercopy之后调用它:
grunt.registerTask('bower',['bowercopy','cleanbowercopy']);
That way it will accomplish what you are seeking within the same command, and can even be reused if you'd rather clean the dir at a different point in time. 这样,它将完成您在同一命令中要查找的内容,并且如果您希望在其他时间点清理目录,甚至可以重用。
I found the asnswer. 我找到了答案。 I was using
clear: true
in the options when it should be clean: true
我在应该
clean: true
的选项中使用了clear: true
clean: true
This works in my gruntfile.js 这在我的gruntfile.js中有效
module.exports = function (grunt) {
// Loads the necessary tasks for this Grunt file.
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
bowercopy: {
options: {
clean: true
},
js: {
options: {
destPrefix: '../../Themes/Theme/assets/'
},
//The key is the destination file. The value is the file from the bower_components folder
//The files will be added to a scripts folder at the location: ../../themes/3MTheme/assets/scripts
//The key is the name of the folder that is copied into the /assets folder.
src : 'scripts'
},
css: {
options: {
destPrefix: '../../Themes/Theme/assets/'
},
src: 'styles'
}
}
// Custom task, executed via the command "grunt bowercopy"
grunt.registerTask('bower', ['bowercopy']);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.