Sapui5应用程序不会使用grunt来简化 [英] Sapui5 app not uglified using grunt

查看:190
本文介绍了Sapui5应用程序不会使用grunt来简化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用grunt和 grunt-sapui5-bestpractice-build 插件来丑化(mangle +删除评论)SapUI5应用。



根据此链接,使用这个插件不应该有一个uglify任务,所以我将它与 grunt-contrib-uglify 插件结合在一起。



我遇到的问题是,在执行应用程序构建时,似乎我的 uglify 任务被忽略,因为 grunt-sapui5-bestpractice-build 有一个隐式的 uglify 任务,它覆盖了我定义的那个。

为了更好的理解,这是code:

package.json
$ b

  {
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


$ b

  module.exports = function(grunt){
'使用严格';
//项目配置。
grunt.initConfig({
uglify:{
options:{
mangle:true,
compress:{
drop_console:true,
dead_code:false,
unused:false
}
},
files:{
展开: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'
]) ;
};

结果是应用程序被正确地构建&缩小,Component-preload.js创建的广告用于加载应用程序,但mangle没有完成,评论仍然存在。



您可以在此提供任何建议?你有什么办法可以用mangle选项输入grunt-sapui5-bestpractice-build来完成这个任务吗?

p>

解决方案

这是更多的扩展评论,而不是一个完整的功能答案。我刚刚用完了空间。
$ b 使 Component-preload.js not 不变的好处在于你可以正常调试它,因为它包含空格,注释等等。调试破坏的代码更加困难。

您必须查看您需要执行的操作完成这个破坏。在'@ 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',//移除`build`文件夹
'clean:dist',//移除`dist`文件夹
'copy:build',//将我所有的代码复制到`build`文件夹
'preload',//将我所有的代码打包到`build`文件夹中并创建一个预加载
'copy:dist:minified',//将损坏的代码复制到`dist`
copy:dist:dbg',//将我的原始代码复制并重命名为`-dbg.js`版本为`dist`
'clean:build'//移除`build`文件夹

这是通过使用gulp-openui5-preload和gulp-uglify等一些gulp完成的。不确定gulp是否在web ide上运行,但我认为你可以在Grunt中重新创建它。

您可以使用类似的方法来修改默认进程的结果并创建一个新的预加载文件,或者可以取消默认设置并尝试完全滚动。

I'm trying to uglify ( mangle + remove comments ) a SapUI5 app by using grunt together with the grunt-sapui5-bestpractice-build plugin.

According to this link, there should not be an uglify task by using this plugin so I've combine it together with the grunt-contrib-uglify plugin.

The problem that I have is; when performing the application build, it seems that my uglify task is being ignored because the grunt-sapui5-bestpractice-build has an implicit uglify task that overwrites the one I'm defining.

For a better understanding, this is the code:

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'
    ]);
};

The result is that the application is correctly built & minified, Component-preload.js is created ad used to load the app but the mangle is not done and the comments are still there.

Could you kindly provide any advice here? Do you have any way to input the grunt-sapui5-bestpractice-build with the mangle option in order to do it just using one plugin?

Thanks in advance.

解决方案

This is more of an extended comment, and not a fully functional answer. I just ran out of space.

The advantage of having the Component-preload.js not mangled is that you can debug it normally, because it contains the spaces, comments etc. Debugging mangled code is more difficult.

You'll have to look at the things you need to do to accomplish this mangling. After '@sap/grunt-sapui5-bestpractice-build' is done, you have minified but not mangled Component.js, a minified but not mangled Comonponent-preload.js and a normal development version in Component-dbg.js, correct?

You might want to abandon the best practice package and go for something else entirely like this: https://www.npmjs.com/package/grunt-openui5. I can't see what happens in the steps in '@sap/grunt-sapui5-bestpractice-build', I can't even find that package anywhere.

Grunt is only executing a series of tasks in a row. I haven't tried the webIDE versions of this but here's the list of tasks I'm executing as part of an offline openui5 app:

'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

This was done with gulp, using packages gulp-openui5-preload and gulp-uglify and some others. Not sure if gulp works on the web ide, but I think you can recreate this in Grunt.

You can either use something like this to mangle the results of the default process and create a new preload file, or you can scrap the default and try to roll your own entirely.

这篇关于Sapui5应用程序不会使用grunt来简化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆