标签: grunt-contrib-uglify

如果目录为空,我如何跳过grunt任务

我正在使用grunt-contrib concatuglify模块来处理一些javascript.目前,如果src/js/为空,它们仍将创建一个(空)concat'd文件,以及缩小版本和源映射.

我想src/js/在继续之前检查文件夹是否为空,并且如果是,则任务应该跳过(不会失败).任何想法如何做到这一点?

gruntjs grunt-contrib-concat grunt-contrib-uglify

8
推荐指数
1
解决办法
2945
查看次数

Grunt Uglify - 忽略特定文件/文件夹

运行uglify时,我需要忽略某些文件和文件夹,但仍然会递归扫描整个文件夹结构.

我有一个concat任务,将我的所有插件连接在一起,并使它们成为一个文件.我需要确保uglify忽略这些文件并且不对它们进行操作,因为我不希望它们在目标目录中,因为concat已经为我处理了这些文件.

我尝试将文件和文件夹添加到我的src数组中,使用前面的!,但它仍然可以对它们进行操作.

以下是我正在尝试使用的内容,但它不起作用:

uglify: {
    options: {
        banner: '/*! <%= grunt.template.today("mm-dd-yyyy h:MM:ss TT") %> */\n'
    },
    files: {
        src: [
                 '!ie'
                ,'!polyfills'
                ,'!vendor'
                ,'!iecompat.js'
                ,'**/*.js'
             ],
        dest: 'app/scripts',
        cwd: 'sources/scripts',
        ext: ".js",
        flatten: false,
        expand: true
    }
},
Run Code Online (Sandbox Code Playgroud)

gruntjs grunt-contrib-uglify

7
推荐指数
1
解决办法
7980
查看次数

使用gruntjs将所有凉亭库合并并缩小

有没有办法将所有凉亭安装的库自动组合并缩小为1个文件?

首先,我尝试了最基本的方法:组合.js所有子目录中的所有文件:

uglify: {
    options: {compress: true},
    my_target: { files: {
        'vendor.js': ['bower_components/**/*.js'],
}   }   }
Run Code Online (Sandbox Code Playgroud)

但这显然是一种糟糕的做法.由于错误太多,它也不起作用.

我手动删除了所有文件,并且只保留了每个库所拥有的1个(主)文件,并且它有效.

有没有办法自动完成这个?

另外,建议这样做吗?(即将所有供应商库合并为1个文件)

minify gruntjs bower grunt-contrib-uglify wiredep

7
推荐指数
2
解决办法
1万
查看次数

尝试使用grunt-contrib-uglify时出错:"src文件为空"

我有以下内容Gruntfile.js:

module.exports = function(grunt) {
  var config = {
    pkg: grunt.file.readJSON('package.json'),

    /* Some other tasks... */

    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },
      def: {
        files: {
          'out/src.js': 'out/src.min.js'
        }
      }
    }
  };

  grunt.initConfig(config);
  grunt.loadNpmTasks('grunt-contrib-uglify');

  grunt.registerTask('default', [/* <other-tasks>, */ 'uglify:def']);
};
Run Code Online (Sandbox Code Playgroud)

文件夹结构如下:

project
  |
  +-out (folder)
  +-Gruntfile.js
Run Code Online (Sandbox Code Playgroud)

重要提示:gruntproject文件夹中运行.

在运行时grunt,有前一个任务uglify:def是负责生成src.jsproject/out.

当我运行时,grunt我可以看到src.js生成project/out,但当Grunt运行时,uglisy:def …

javascript gruntjs grunt-contrib-uglify

6
推荐指数
1
解决办法
4934
查看次数

当我运行Grunt时,我收到以下消息:找不到本地npm模块"grunt-contrib-copy".它安装了吗?

我一直在尝试安装Grunt.当我运行grunt时,我收到以下消息和警告列表:

Local Npm module "grunt-contrib-copy" not found.  Is it installed?
Local Npm module "grunt-contrib-uglify" not found.  Is it installed?
Local Npm module "grunt-contrib-jshint" not found.  Is it installed?
Local Npm module "grunt-contrib-less" not found.  Is it installed?
Local Npm module "grunt-contrib-clean" not found.  Is it installed?
Local Npm module "grunt-contrib-watch" not found.  Is it installed?
Local Npm module "grunt-contrib-concurrent" not found.  Is it installed?
Local Npm module "grunt-contrib-nodemon" not found.  Is it installed?
Local Npm module "grunt-contrib-newer" not found.  Is …
Run Code Online (Sandbox Code Playgroud)

node.js npm grunt-contrib-watch grunt-contrib-copy grunt-contrib-uglify

6
推荐指数
1
解决办法
1万
查看次数

当字符串以`字符开头时,Grunt uglify抛出解析错误

我正在运行grunt uglify任务来缩小我的js文件但是当字符串以`字符开头时它给我​​错误.

我的字符串看起来像这样

var html = `<div class='list-item'>
              <span>ABC</span>
           </div>`;
Run Code Online (Sandbox Code Playgroud)

我的Gruntfile.js uglifyjs块是这样的

uglify: {
  'dev': {
       options: {
          mangle: false
       },
       files: {
          'common/utility_functions.js': ['common/utility_functions.js']
       }
   }
}
Run Code Online (Sandbox Code Playgroud)

当我运行grunt uglify时,它给了我以下错误

>> Uglifying source common/utility_functions.js failed.
   Warning: Uglification failed.
   SyntaxError: Unexpected character '`'.
   Line 162 in common/utility_functions.js
   Use --force to continue.
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮忙解决这个问题吗?我认为使用`字符是有效的.它在jshint过程中没有给我错误,因为我在jshint选项中添加了enext:true.

gruntjs grunt-contrib-uglify

6
推荐指数
1
解决办法
2188
查看次数

'El Capitan'是无根的打破旧的咕噜声吗?

迁移到El Capitan之后,用户似乎遇到了grunt安装的问题,可能与El Capitan的无根变化有关.特别是,运行grunt --force命令会导致EPERM错误.工作流程如下:

假设已经安装了npm,使用package.json和gruntfile.js导航到grunt目录并调用grunt:

grunt --force
Run Code Online (Sandbox Code Playgroud)

示例Gruntfile.js文件内容:

module.exports = function(grunt) {

    // All configuration goes here 
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        concat: {
            // Configuration for concatenating files goes here.
            dist: {
                src: [
                        '../js/libs/owl.carousel.js',
                        '../js/libs/jquery.actual.js',
                        '../js/libs/chosen.jquery.js',
                        '../js/libs/jquery.parallax.js',
                        '../js/src/common.js'  
                ],
                dest: '../js/pro/global.js',
            },
        },

        uglify: {
            build: {
                src: '../js/pro/global.js',
                dest: '../js/pro/global.min.js',
            },
        },


        imagemin: {
            dynamic: {
                files: [{
                    expand: true,
                    cwd: '../img/src/',
                    src: ['**/*.{png,jpg,gif}'],
                    dest: '../img/pro/'
                }]
            }
        },

        compass: {
            dev: {
                options: {              
                    sassDir: '../sass',
                    cssDir: '../css', …

node.js gruntjs grunt-contrib-concat grunt-contrib-watch grunt-contrib-uglify

5
推荐指数
1
解决办法
849
查看次数

在Grunt(Yeoman)中禁用缩小

我最近开始通过Yeoman使用GruntJS,我喜欢Javascript缩小的想法,但它在开发过程中遇到了困难.我试图在Gruntfile中以不同的组合禁用uglify,usemin等,但是一切似乎都依赖于另一件事并打破了这个过程.有没有简单的方法来禁用缩小?我使用Yeoman提供的最新版本的Grunt,我发现旧的解决方案与使用Yeoman的用户有不同的Gruntfile设置.

这是我的Gruntfile:

// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
  options: {
    dest: '<%= config.dist %>'
  },
  html: '<%= config.app %>/index.html'
},
Run Code Online (Sandbox Code Playgroud)

http://hastebin.com/gicabukojo.js

javascript minify gruntjs grunt-contrib-uglify

5
推荐指数
1
解决办法
2753
查看次数

grunt uglify bower_components文件夹

所以我的项目安装了很多插件 bower

所有这些都在他们自己的自定义文件夹中,包含在bower_components文件夹中

现在我想运行一个grunt基本上需要所有这些和uglify它们的脚本.

所以我创建了以下脚本:

    module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        copy: {
            dist: {
                files: [ {src: 'index.html', dest: 'dist/index.html'} ]
            }
        },

        'useminPrepare': {
            options: {
                dest: 'dist'
            },
            html: 'index.html'
        },

        usemin: {
            html: ['dist/index.html']
        }
    });

    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-usemin');

    grunt.registerTask('default', ['useminPrepare', 'copy', 'concat', 'uglify', 'usemin']);
};
Run Code Online (Sandbox Code Playgroud)

取自另一个SO问题

但是每当我运行这个时,我都会收到以下警告/错误:

没有找到"concat"目标.警告:任务"concat"失败.使用--force继续.因警告而中止.

谁能告诉我我做错了什么?

我的index.html样子如何:

    <!DOCTYPE html>
<html lang="en" data-ng-app="app" ng-controller="AppCtrl">
<head>
    <script src="js/newrelic.js"></script>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, …
Run Code Online (Sandbox Code Playgroud)

javascript gruntjs grunt-contrib-uglify

5
推荐指数
1
解决办法
334
查看次数

如何在 grunt 任务中将 ngAnnotate 替换为 babel-plugin-angularjs-annotate

我正在使用 Angular JS (1.6),我在 grunt 中有以下任务用于缩小角度模块

ngAnnotate: {
  dist: {
    files: [{
      expand: true,
      cwd: '.tmp/concat/scripts',
      src: '*.js',
      dest: '.tmp/concat/scripts'
    }]
  }
}
Run Code Online (Sandbox Code Playgroud)

但上述任务不支持 ES2015 和 ES2016 功能如何 在 iegrunt 文件中的grunt任务中添加babel-plugin-angularjs-annotate

angularjs bundling-and-minification gruntjs grunt-contrib-uglify gruntfile

5
推荐指数
1
解决办法
2415
查看次数