【发布时间】:2016-01-15 10:55:59
【问题描述】:
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']);
};
有没有什么办法可以让这段代码更小,而不是有很多单独的复制命令?
谢谢
【问题讨论】:
-
类似 browersify 的东西会对此有所帮助。由于 browersify 致力于将各个包的 package.json 的
main字段中提到的文件捆绑在一起的概念,它适用于您的用例。如果你想在 npm 包的main字段之外获取文件,你可以使用像browserify-shim这样的转换。同样对于捆绑 CSS ,像parcelify这样的转换会很有帮助
标签: javascript gruntjs grunt-contrib-copy