繁体   English   中英

如何使用Grunt将主文件复制到特定文件夹

[英]How copy mains file to specific folder with Grunt

我的.bowerrc是这样的:

{
  "directory": "components",
  "strict-ssl": true
}

在bower.json中,我有:

"dependencies": {
  "jquery": "~2.1.1",
  "bootstrap": "~3.3.1"
}

当我运行bower install时 ,它将jquerybootstrap下载到components文件夹。

我正在尝试使用Grunt生成如下的结构,但是,我找不到能做到这一点的插件。

build /
      js/jquery.min.js
      js/bootstrap.min.js
      css/bootstrap.min.css
      fonts/glyphicons-halflings-regular.eot
      fonts/glyphicons-halflings-regular.svg
      fonts/glyphicons-halflings-regular.ttf
      fonts/glyphicons-halflings-regular.woff

复制这些文件后,我想压缩(我知道如何执行此步骤)构建文件夹中的内容。

您可以使用grunt-bower-taks实现此目的。 该任务将负责使用Bower下载文件并将其放置在所需的结构中。
您将需要指定与您所需的文件夹结构相匹配的自定义布局。 这是通过在任务选项中添加自定义布局功能来完成的:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    bower: {
      install: {
        options: {
            targetDir: "./build",
            verbose: true,
            layout: function(type, component, source) {
              return type;
            }
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-bower-task');
}; 

由于您想要的不仅仅是“主要”文件,因此您还需要在exportsOverride添加一个exportsOverride部分:

"exportsOverride": {
    "jquery": {
      "js": "dist/*.js"
    },
    "bootstrap": {
      "js": "dist/js/*.js",
      "css" : "dist/css/*.css",
      "fonts" : "dist/fonts/*.*"
    }
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM