JS 文件在 Grunt concat 任务中重复
JS files getting duplicate in Grunt concat task
我遇到了一个奇怪的问题,在 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 对所有节点模块使用最新的依赖项。
好的,我通过将 --verbose
标志传递给 grunt build
命令找到了解决方案。问题是有两个 bower_components
,一个在我的当前目录 (.) 中,另一个在 ./app
目录中,因为我的 usemin 块 build:js({app,.})
正在读取两个位置,即 .
和 ./app
,因此 Grunt 的连接任务正在复制所有文件。
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
因此,从 app
目录中删除 bower_components
目录解决了这个问题。希望这可能对其他人有所帮助。
我遇到了一个奇怪的问题,在 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 对所有节点模块使用最新的依赖项。
好的,我通过将 --verbose
标志传递给 grunt build
命令找到了解决方案。问题是有两个 bower_components
,一个在我的当前目录 (.) 中,另一个在 ./app
目录中,因为我的 usemin 块 build:js({app,.})
正在读取两个位置,即 .
和 ./app
,因此 Grunt 的连接任务正在复制所有文件。
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
因此,从 app
目录中删除 bower_components
目录解决了这个问题。希望这可能对其他人有所帮助。