Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 让sourcemaps与Grunt、usemin、uglify和rev一起工作_Angularjs_Gruntjs_Source Maps_Grunt Usemin_Grunt Contrib Uglify - Fatal编程技术网

Angularjs 让sourcemaps与Grunt、usemin、uglify和rev一起工作

Angularjs 让sourcemaps与Grunt、usemin、uglify和rev一起工作,angularjs,gruntjs,source-maps,grunt-usemin,grunt-contrib-uglify,Angularjs,Gruntjs,Source Maps,Grunt Usemin,Grunt Contrib Uglify,我正在使用Grunt优化AngularJS应用程序以用于生产。它使用useminPrepare和usemin从my index.html页面读取要压缩/缩小的文件。我正在尝试让sourcemaps工作,以便查看发生错误的位置。以下是package.json的相关版本: "grunt": "0.4.5", "grunt-autoprefixer": "2.2.0", "grunt-contrib-clean": "~0.5.0", "grunt-contrib-concat": "~0.3.0",

我正在使用Grunt优化AngularJS应用程序以用于生产。它使用useminPrepare和usemin从my index.html页面读取要压缩/缩小的文件。我正在尝试让sourcemaps工作,以便查看发生错误的位置。以下是package.json的相关版本:

"grunt": "0.4.5",
"grunt-autoprefixer": "2.2.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-cssmin": "~0.11.0",
"grunt-contrib-uglify": "~0.9.1",
"grunt-rev": "~0.1.0",
"grunt-usemin": "~2.0.2",
下面是我的
Gruntfile.js
的精简版,仅用于相关任务:

'use strict';

// usemin custom step
var useminAutoprefixer = {
    name: 'autoprefixer',
    createConfig: require('grunt-usemin/lib/config/cssmin').createConfig // Reuse cssmins createConfig
};

module.exports = function (grunt) {
    require('load-grunt-tasks')(grunt);

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        clean: ["dist", '.tmp'],
        copy: {
            main: {
                files: [
                    {
                        expand: true,
                        src: ['**', '!css/**', '!*.js', '!node_modules/**', '!*.log', '!tests/**'],
                        dest: 'dist/'
                    }
                ]
            }
        },
        cssmin: {
            options: {
                root: './' // Replace relative paths for static resources with absolute path
            }
        },
        rev: {
            files: {
                src: ['dist/assets/**/*.{js,css}']
            }
        },
        useminPrepare: {
            html: 'index.html',
            options: {
                flow: {
                    html: {
                        steps: {
                            js: ['concat', 'uglifyjs'],
                            css: ['cssmin', useminAutoprefixer] // Let cssmin concat files so it corrects relative paths to fonts and images
                        },
                        post: {
                            js: [{
                                name: 'concat',
                                createConfig: function (context, block) {
                                    context.options.generated.options = {
                                        sourceMap: true
                                    };
                                }
                            }, {
                                name: 'uglifyjs',
                                createConfig: function (context, block) {
                                    context.options.generated.options = {
                                        sourceMapIn: '.tmp/concat/' + block.dest.replace('.js', '.js.map'),
                                        mangle: false,
                                        beautify: {
                                            beautify: true
                                        }
                                    };
                                }
                            }]
                        }
                    }
                }
            }
        },
        usemin: {
            html: ['dist/index.html']
        },
        uglify: {
            options: {
                report: 'min',
                mangle: false
            },
            generated: {
                options: {
                    sourceMap: true
                }
            }
        }
    });

    grunt.registerTask('build', [
        'clean', 'useminPrepare', 'concat', 'copy', 'cssmin', 'autoprefixer', 'uglify', 'rev', 'usemin'
    ]);
};
*.js.map
文件正在
dist/assets/js
中生成。而经过修订的JS文件似乎很好地引用了它们:

//# sourceMappingURL=app.js.map
但是,在sourcemap中,它可能有一个错误的目录路径和文件名:

{"version":3,"file":"app.js","sources":["../../../.tmp/concat/assets/js/app.js"] ...
知道如何让sourcemaps与Grunt、usemin、uglify和rev一起工作吗