Javascript GruntJS可以在复制文件后删除bower_components文件夹吗?
我正在使用Bower和GruntJS。我原以为grunt bowercopy在完成后会删除Javascript GruntJS可以在复制文件后删除bower_components文件夹吗?,javascript,gruntjs,bower,Javascript,Gruntjs,Bower,我正在使用Bower和GruntJS。我原以为grunt bowercopy在完成后会删除bower\u components文件夹,但事实并非如此 grunt bowercopy能否在将文件复制到所需位置后删除bower_components文件夹 以下是我的文件夹设置: ->Project ->Themes ->Theme ->assets ->scripts
bower\u components
文件夹,但事实并非如此
grunt bowercopy能否在将文件复制到所需位置后删除bower_components文件夹
以下是我的文件夹设置:
->Project
->Themes
->Theme
->assets
->scripts
->styles
->tools
->build
->bower_components
->bower.json
->gruntfile.js
->package.json
下面是我如何在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']);
};
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']);
};
我找到了答案。我在选项中使用了
clear:true
,而它应该是clean:true
这在我的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: {
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']);
};
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']);
};
看起来grunt bowercopy并没有为您这样做,但我已经做了类似的事情,在运行测试命令之前清除报告 只需创建自己的自定义任务,名为cleanbowercopy,该任务在正在清理的目录上执行 然后更新注册任务以在bowercopy之后调用它:
grunt.registerTask('bower',['bowercopy','cleanbowercopy']);
这样,它就可以在同一个命令中完成所需的任务,如果您希望在不同的时间点清理目录,它甚至可以重复使用。如果它在您构建项目后删除bower_components文件夹,您将需要在下一次构建中再次安装这些组件,对吗?为什么要删除该文件夹?它只用于开发目的,不进入dist文件夹。@Sergey,我正在从共享服务器复制一些文件。这些文件可能会被其他人偶尔更新,我想确保我拉下这些最新的更新。谢谢!这真是个好主意。看起来grunt bowercopy将删除bower_components文件夹,我只是在发布到这里之后才发现我的错误。