Angular grunt build (from yeoman) breaks my app

后端 未结 5 2013
野趣味
野趣味 2021-01-12 09:33

after running the build from the /dist folder I get:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.1/$injector/modulerr?p         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-12 09:54

    I will try to be brief explaining the problem when building with usemin 2.0.x and ngmin in Angularjs (according my experience, I may be wrong in something, if yes please correct me):

    The normal flow in the Build grunt task is that ngmin is executed before usemin and others, to let the code with injections like this:

    ...
    angular.module("Config",[])
        .config(["$httpProvider","CONSTANTS","ERRORS","HEADERS",function(a,b,c,d){var
    ...
    

    usemin 0.1.x was using only 'concat', but the version 2.0.x is using 'concat' and 'uglifyjs' so, after concatenate the code, it changes the javascript code again, this corrupts the ngmin, as you can see in the following example:

    ...
    angular.module("Config",[])
        .config(function(a,b,c,d){var
    ...
    

    So you have to stop it defining the flow in useminPrepare, like the following:

    useminPrepare: {
            html: '<%= yeoman.app %>/index.html',
            options: {
                dest: '<%= yeoman.dist %>',
                flow: {
                    steps: {'js': ['concat']},
                    post: {}
                }
            }
        },
    

    Edit You can add the task in the grunt tasks:

    grunt.registerTask('build', [ 
        'clean:dist', 
        'jshint', 
        'useminPrepare', 
        'imagemin', 
        'cssmin', 
        'ngmin', 
        'uglify', 
        'rev', 
        'usemin'
    ])
    

    Hope it helps!

提交回复
热议问题