在 Grunt 中复制 dist 文件的更有效方法
More efficient way of copying dist files in Grunt?
gruntjs的新功能,目前正在使用它将一些npm发行版移动到public/js文件夹。
这是代码:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
bootstrapCss: {
src: "./node_modules/bootstrap/dist/css/bootstrap.css",
dest: "./public/css/bootstrap.css"
},
bootstrapTheme: {
src: "./node_modules/bootstrap/dist/css/bootstrap-theme.css",
dest: "./public/css/bootstrap-theme.css"
},
bootstrap: {
src: "./node_modules/bootstrap/dist/js/bootstrap.js",
dest: "./public/js/libs/bootstrap.js"
},
backbone: {
src: "./node_modules/backbone/backbone.js",
dest: "./public/js/libs/backbone.js"
},
backboneLocalstorage: {
src: "./node_modules/backbone.localstorage/backbone.localStorage.js",
dest: "./public/js/libs/backbone.localStorage.js"
},
requireJs: {
src: "./node_modules/requirejs/require.js",
dest: "./public/js/libs/requirejs.js"
},
underscore: {
src: "./node_modules/underscore/underscore.js",
dest: "./public/js/libs/underscore.js"
},
jquery: {
src: "./node_modules/jquery/dist/jquery.js",
dest: "./public/js/libs/jquery.js"
},
requireJsText: {
src: "./node_modules/requirejs-text/text.js",
dest: "./public/js/libs/requirejs-text.js"
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-copy');
// Default task(s).
grunt.registerTask('default', ['copy']);
};
有没有办法使这段代码更小,而不是有很多单独的复制命令?
谢谢
我会在我的
copy
配置中创建两个目标来实现这一点,一个用于JS,一个用于CSS。我会使用 Grunt 提供的一些功能来动态构建 files
对象,以使我免于键入和维护每个目标路径。这样,当我想添加文件时,我只需要将它们的路径添加到相应的src
数组中。
grunt.initConfig({
copy: {
js: {
expand: true,
cwd: './node_modules',
dest: './public/js/libs/',
flatten: true,
filter: 'isFile',
src: [
'./bootstrap/dist/js/bootstrap.js',
'./backbone/backbone.js',
'./backbone.localstorage/backbone.localStorage.js',
'./requirejs/require.js',
'./underscore/underscore.js',
'./jquery/dist/jquery.js',
'./requirejs-text/text.js'
]
},
css: {
expand: true,
cwd: './node_modules',
dest: './public/css/',
flatten: true,
filter: 'isFile',
src: [
'./bootstrap/dist/css/bootstrap.css',
'./bootstrap/dist/css/bootstrap-theme.css'
]
}
}
});
相关文章:
- 在jQuery中创建向下滑动子菜单的最有效方法
- 使用Underscore.js修改json数组中所选元素的更有效方法
- 选择具有值数组的所有元素的最有效方法
- 将JSON存储和恢复到此Ionic应用程序的最有效方法
- 将javascript数组中的项移动到特定位置的有效方法
- 将JS对象数组转换为嵌套形式的最有效方法
- 隐藏具有特定类$.each、for等的元素的有效方法
- 什么's是调用具有可变参数的函数的有效方法
- 选择具有特定数据的所有 html 标记的最有效方法是什么 - [适当性],无论值如何
- 使用 jQuery 调用 PHP 端点的最有效方法
- 这是解析 Int 的有效方法吗?
- 在JavaScript中搜索数组映射的最有效方法
- 获取字符串中最后一个换行符的最有效方法是什么
- 什么's是在两个(或多个)阵列中找到匹配的细胞序列的最有效方法
- 什么's是在IE8+中添加元素的最有效方法
- 从任何jquery选择器字符串创建元素的最有效方法
- 在日期范围内查找丢失日期的最有效方法是什么
- 对区间[1,10^12]中的整数进行编码/解码的快速有效方法是什么
- 在条件(if)结构的条件语句中是否有定义变量的有效方法
- 在ASP.NET中使用JQuery UI自动完成的有效方法