JS文件在Grunt concat任务中得到重复

时间:2015-05-05 14:24:03

标签: gruntjs grunt-contrib-concat

我面临着一个奇怪的问题,即在Grunt concat之后,我的一些usemin块中的文件在Grunt构建任务中被复制了。

我已经搜索过它并找到了Grunt my code is duplicated in concat.js之类的各种答案,但无法解决问题。

我使用默认生成的Gruntfile.js配置(通过yoman)

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

    grunt.registerTask('build', [
        'clean:dist',
        //'wiredep',
        'useminPrepare',
        'concurrent:dist',
        'autoprefixer',
        'concat',
        'ngAnnotate',
        'copy:dist',
        'cdnify',
        'cssmin',
        'uglify',
        'filerev',
        'usemin',
        'htmlmin',
    ]);

我的usemin块看起来像:

<!-- build:js({app,.}) scripts/vendor.js -->
    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/angular-resource/angular-resource.js"></script>
    <script src="bower_components/angular-cookies/angular-cookies.js"></script>
    <script src="bower_components/angular-animate/angular-animate.js"></script>
    <script src="bower_components/angular-sanitize/angular-sanitize.min.js"></script>
    <script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
    <script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
    <script src="bower_components/angular-translate/angular-translate.js"></script>
    <script src="bower_components/angular-translate-loader-partial/angular-translate-loader-partial.js"></script>
    <script src="bower_components/augment/augment.js"></script>
<!-- endbuild -->

使用最新nodejs和npm的所有节点模块的最新依赖项。

1 个答案:

答案 0 :(得分:0)

好的,我通过将--verbose标志传递给grunt build命令来找出解决方案。问题是有两个bower_components,一个在我当前的目录(。)中,另一个在./app目录,因为我的usemin块build:js({app,.})正在读取两个位置,即{{ 1}}和.,因此Grunt的concat任务是复制所有文件。

./app

因此,从Reading ./bower_components/angular/angular.js...OK Reading app/bower_components/angular/angular.js...OK Reading ./bower_components/angular-resource/angular-resource.js...OK Reading app/bower_components/angular-resource/angular-resource.js...OK Reading ./bower_components/angular-cookies/angular-cookies.js...OK Reading app/bower_components/angular-cookies/angular-cookies.js...OK Reading ./bower_components/angular-animate/angular-animate.js...OK Reading app/bower_components/angular-animate/angular-animate.js...OK Reading ./bower_components/angular-sanitize/angular-sanitize.min.js...OK Reading app/bower_components/angular-sanitize/angular-sanitize.min.js...OK Reading ./bower_components/angular-ui-router/release/angular-ui-router.js...OK Reading app/bower_components/angular-ui-router/release/angular-ui-router.js...OK Reading ./bower_components/angular-bootstrap/ui-bootstrap-tpls.js...OK Reading app/bower_components/angular-bootstrap/ui-bootstrap-tpls.js...OK Reading ./bower_components/angular-translate/angular-translate.js...OK Reading app/bower_components/angular-translate/angular-translate.js...OK Reading ./bower_components/angular-translate-loader-partial/angular-translate-loader-partial.js...OK Reading app/bower_components/angular-translate-loader-partial/angular-translate-loader-partial.js...OK Reading ./bower_components/augment/augment.js...OK Reading app/bower_components/augment/augment.js...OK 目录中删除bower_components目录修复了问题。希望这对其他人有所帮助。