javascript - 如何用grunt-contrib-uglify给多文件生成source-map
迷茫
迷茫 2017-04-10 12:46:54
[JavaScript讨论组]

这里也有个问题:http://stackoverflow.com/questions/14207983/how-to-specify-multiple-source-maps-in-uglify-grunt-task

参考了这里 http://flippinawesome.org/2013/07/01/building-a-javascript-library-with-grunt-js/

module.exports = function(grunt) {
  var bannerContent = '... banner template ...';
  var name = '<%= pkg.name %>-v<%= pkg.version%>';  

  grunt.initConfig({
    // pkg must be defined inside initConfig object
    pkg : grunt.file.readJSON('package.json'),
    // uglify configuration
    uglify: {
      options: {
        banner: bannerContent,
        sourceMapRoot: '../',
        sourceMap: 'distrib/'+name+'.min.js.map',
        sourceMapUrl: name+'.min.js.map'
      },
      target : {
        src : ['src/**/*.js'],
        dest : 'distrib/' + name + '.min.js'
      }
    },
    concat: { /* ... concat configuration ... */ },
    jshint: { /* ... jshint configuration ... */ }
  });

  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.registerTask('default', ['jshint', 'concat', 'uglify']);
};

我的配置

uglify : {
            options : {
                banner:'/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
                sourceMapRoot: '../',
                sourceMap:'dist/' + '.map',
                sourceMapUrl: '.min.js.map'
            },
            main:{
                files: [
                    {
                        expand: true,
                        cwd: 'dist/',
                        src: ['js/**/*.js', '!js/**/*-debug.js'],
                        dest: 'dist/'
                    }
                ]
            }
        }

最后只生成了一个 .min.js.map,只是对一个js的map,没达到目录下所有的js的source-map效果

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(1)
黄舟

参考上面 http://stackoverflow.com/a/17503492

uglify : {
            options : {
                banner:'/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
                sourceMapRoot: './dist/map/',
                sourceMap:function(path) { return path.replace(/js/,'map').replace('.js',".map")}
            },
            main:{
                files: [
                    {
                        expand: true,
                        cwd: 'dist/',
                        src: ['js/**/*.js', '!js/**/*-debug.js'],
                        dest: 'dist/'
                    }
                ]
            }
        }

解决

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号