gpt4 book ai didi

javascript - Grunt useminPrepare 和 usemin 不能处理多个任务和文件(concat 失败)

转载 作者:行者123 更新时间:2023-11-30 15:55:01 24 4
gpt4 key购买 nike

我想在我的项目中有两个目标。一个用于管理员,一个用于用户页面。出于性能原因,我不希望将管理插件包含在用户页面中。但是我在尝试运行构建时遇到此错误:

Running "useminPrepare:admin" (useminPrepare) task
Configuration changed for concat, uglify, cssmin

Running "useminPrepare:user" (useminPrepare) task
Configuration changed for concat, uglify, cssmin

No "concat" targets found.
Warning: Task "concat" failed. Use --force to continue.

我在 GruntFile.js 中找不到 concat 任务来查看问题所在。我的 GruntFile.js 使用任务如下:

    useminPrepare: {
admin: {
html: 'app/admin-index.html',
options: {
dest: 'dist'
}
},
user: {
html: 'app/index.html',
options: {
dest: 'dist'
}
},
},
usemin: {
admin: {
html: 'dist/admin-index.html'
},
user: {
html: 'dist/index.html'
}
}

grunt.registerTask('build', [
'clean:dist',
'less',
'useminPrepare:admin',
'useminPrepare:user',
'concat',
'copy:dist',
'cssmin',
'uglify',
'filerev',
'usemin:admin',
'usemin:user',
'htmlmin'
]);

而 html 对应的是 js 文件。首先是 admin-index.html:

<!-- build:js(.) scripts/vendor.js -->

<!-- jQuery and Bootstrap -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>

<!-- MetsiMenu -->
<script src="bower_components/metisMenu/dist/metisMenu.min.js"></script>

<!-- Peace JS -->
<script src="bower_components/pace/pace.min.js"></script>

<!-- Angular scripts-->
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>

<!-- Angular Dependiences -->
<!-- -->
<!-- -->
<!-- -->

<!-- Datatables -->
<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<script src="bower_components/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
<script src="bower_components/jszip/dist/jszip.min.js"></script>
<script src="bower_components/pdfmake/build/pdfmake.min.js"></script>
<script src="bower_components/pdfmake/build/vfs_fonts.js"></script>
<script src="bower_components/datatables.net-buttons/js/buttons.html5.min.js"></script>
<script src="bower_components/datatables.net-buttons/js/buttons.print.min.js"></script>
<script src="bower_components/datatables.net-buttons/js/buttons.colVis.min.js"></script>

<!-- Datepicker -->
<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<script src="bower_components/bootstrap-datepicker/dist/locales/bootstrap-datepicker.tr.min.js"></script>
<script src="bower_components/datepair.js/dist/datepair.js"></script>

<!-- Timepicker -->
<script src="bower_components/jt.timepicker/jquery.timepicker.js"></script>

<!-- endbuild -->

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<!-- Custom and plugin javascript -->
<script src="scripts/inspinia.js"></script>

<!-- Anglar App Script -->
<script src="scripts/app.js"></script>
<script src="scripts/config.js"></script>
<script src="scripts/directives.js"></script>
<script src="scripts/controllers.js"></script>
<!-- endbuild -->

现在是 index.html 文件:

<!-- build:js(.) scripts/uivendor.js -->

<!-- jQuery and Bootstrap -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>

<!-- Datepicker -->
<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<script src="bower_components/bootstrap-datepicker/dist/locales/bootstrap-datepicker.tr.min.js"></script>

<!-- endbuild -->

最佳答案

也许您在 Gruntfile.js 的 initConfig 设置中没有上面的 concat 参数,但在“BUILD”命令中设置了它。 Grunt 不知道连接字符串与什么有关,所以它会抛出一个错误

尝试像下面这样删除'concat'

grunt.registerTask('build', [
'clean:dist',
'less',
'useminPrepare:admin',
'useminPrepare:user',
'copy:dist',
'cssmin',
'uglify',
'filerev',
'usemin:admin',
'usemin:user',
'htmlmin'
]);

或在下面的配置设置示例中添加一个 concat 键

  concat: {
options: {
separator: ';',
},
dist: {
src: ['src/file1.js', 'src/file2.js', 'src/file3.js'],
dest: 'dist/concat-file.js',
},
},

关于javascript - Grunt useminPrepare 和 usemin 不能处理多个任务和文件(concat 失败),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38696714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com