简体   繁体   English

配置grunt.js以逐个缩小Bower文件夹中的文件

[英]Configure grunt.js to minify files one by one in bower folder

I have the dependencies of the application in bower_components , some of the dependencies don't have a minified version so I'd like to create a task creates a minified copy of the file version in the same place where the file is located like: 我在bower_components中具有应用程序的依赖 ,其中一些依赖项没有缩小版本,因此我想创建一个任务,在文件所在的相同位置创建文件版本的缩小副本,例如:

  • bower_components bower_components
    • lib1 LIB1
      • lib1.js lib1.js
      • lib1.min.js <- create this file if doesn't exist lib1.min.js <-如果不存在则创建此文件
    • lib2 LIB2
      • lib2.js lib2.js
      • lib2.min.js <- create this file in it's own lib2 folder lib2.min.js <-在它自己的lib2文件夹中创建此文件
    • lib3 LIB3
      • lib3.js lib3.js
      • lib3.min.js <- and so on... lib3.min.js <-依此类推...

This is my grunt Config so far: 到目前为止,这是我最讨厌的配置:

 uglify: {
        dev: {
            files:[
            {
                expand: true,
                src: 'bower_components/modernizr/modernizr.js',
                dest: '/',
                ext:'.min.js'
            }, {
                expand: true,
                src: 'bower_components/angular-facebook/lin/angular-facebook.js',
                dest: '/',
                ext: '.min.js'
            }]
            },
                main: {
                    src: 'temp/app.min.js',
                    dest:'dist/app.min.js'
                }
            }

the Grunt task says that copied modernizr to it's own folder but when I look at it, the file is not there and after the first file Grunt passes to the next task and ignores the 'second' file in the array. Grunt任务说复制了modernizr到它自己的文件夹,但是当我查看它时,文件不存在,在第一个文件Grunt传递到下一个任务之后,它忽略了数组中的“第二个”文件。

I was just testing this obviously I'd like to implement a way that grunt scan all the dependencies in bower_components automatically. 我只是在测试这一点,显然我想实现一种方法, 可以自动扫描 bower_components中的 所有 依赖

btw, I don't mind to change the task to any other library. 顺便说一句,我不介意将任务更改为任何其他库。

the / in your dest -option means the root path (were your gruntfile resides). dest -option中的/表示根路径(您的gruntfile位于其中)。 just delete the dest -option or put an empty string there. 只需删除dest -option或在其中放置一个空字符串即可。

important: this just works with the expand -option set! 重要:这仅适用于expand -option设置!

{
  expand: true,
  src: 'bower_components/modernizr/modernizr.js',
  ext:'.min.js'
}

Edit: 编辑:

for scanning all folders an minimizing all js files do it like this (note the second argument in src to not minify files which are already minified): 要扫描所有文件夹,请最小化所有js文件,方法是这样的(请注意src中的第二个参数不缩小已经缩小的文件):

{
  expand: true,
  src: ['bower_components/**/*.js', '!bower_components/**/*.min.js'],
  ext:'.min.js'
}

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

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