我试图通过与SapUI5插件一起使用grunt来丑化( mangle +删除注释)一个grunt-sapui5-bestpractice-build应用程序。
根据这个链接,使用这个插件不应该有一个丑陋的任务,所以我已经将它与grunt-contrib-uglify插件结合在一起了。
我遇到的问题是:在执行应用程序构建时,我的uglify任务似乎被忽略了,因为grunt-sapui5-bestpractice-build有一个隐式uglify任务,它覆盖了我定义的任务。
为了更好地理解,以下是代码:
package.json
{
"name": "grunt-build",
"version": "0.0.1",
"description": "Grunt build",
"private": true,
"devDependencies": {
"@sap/grunt-sapui5-bestpractice-build": "1.3.33",
"grunt-contrib-uglify": "3.3.0"
}
}Gruntfile.js
module.exports = function(grunt) {
'use strict';
// Project configuration.
grunt.initConfig({
uglify: {
options: {
mangle: true,
compress: {
drop_console: true,
dead_code: false,
unused: false
}
},
files: {
expand: true,
cwd: "<%= ref.staging%>",
src: ["**/*.js", '!test/**', '!test_local.html'],
dest: "<%= ref.process%>"
}
}
});
grunt.loadNpmTasks('@sap/grunt-sapui5-bestpractice-build');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('default', [
'lint',
'clean',
'build',
'uglify'
]);
};其结果是,应用程序被正确构建&小型化,组件预加载. is被创建为用于加载应用程序的广告,但未完成处理,注释仍然存在。
您能在这里提供任何建议吗?你有任何方法输入咕噜-智人5-最佳实践-构建与mangle选项,以做它只是使用一个插件?
提前谢谢。
发布于 2018-02-23 07:32:16
这更多的是一个扩展的评论,而不是一个功能齐全的回答。我刚用完了空间。
使Component-preload.js不损坏的优点是您可以正常地调试它,因为它包含空格、注释等。调试故障代码比较困难。
你得看看你需要做些什么来完成这件事。在'@sap/grunt-sapui5-bestpractice-build'完成之后,您已经缩小了但没有损坏的Component.js,缩小了但没有损坏的Comonponent-preload.js,以及Component-dbg.js中的正常开发版本,对吗?
您可能希望放弃最佳实践包,转而进行其他完全类似的事情:https://www.npmjs.com/package/grunt-openui5。我看不到在'@sap/grunt-sapui5-bestpractice-build'中的步骤中会发生什么,我甚至在任何地方都找不到那个包。
Grunt只在一行中执行一系列任务。我还没有尝试过这个webIDE版本,但下面列出了作为脱机openui5应用程序的一部分正在执行的任务列表:
'clean:build', // remove `build` folder
'clean:dist', // remove `dist` folder
'copy:build', // copy all my code to the `build` folder
'preload', // mangle all my code in the `build` folder and create a preload
'copy:dist:minified', // copy the mangled code to `dist`
'copy:dist:dbg', // copy and rename my original code as `-dbg.js` versions to `dist`
'clean:build' // remove the `build` folder这是用gulp做的,使用包gulp 5-预加载和吞咽-丑陋和其他一些。不确定gulp是否能在web ide上工作,但我认为您可以在Grunt中重新创建这个功能。
您可以使用这样的东西来破坏默认进程的结果并创建一个新的预加载文件,或者您可以放弃默认并尝试完全滚动自己的文件。
https://stackoverflow.com/questions/48811997
复制相似问题