0

我遇到了一个奇怪的问题,在 Grunt concat 之后,我在 usemin 块中的一些文件在 Grunt 构建任务中被重复了。

我已经搜索过它并发现了各种答案,例如Grunt 我的代码在 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 对所有节点模块使用最新的依赖项。

4

1 回答 1

0

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

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从目录中删除app目录解决了这个问题。希望这对其他人有帮助。

于 2015-05-05T15:40:54.657 回答