简体   繁体   English

停止Gulp删除未使用的Javascript函数

[英]Stop Gulp Removing Unused Javascript Functions


I am using Gulp via a Laravel project and I have javascript functions that I keep in one file that I then reference from the template when the page loads. 我正在通过Laravel项目使用Gulp,我将javascript函数保存在一个文件中,然后在页面加载时从模板中引用该文件。

The issue is Gulp removes unused functions when it complies the javascript files. 问题是Gulp在编译javascript文件时会删除未使用的功能。

Is there a way to stop this behaviour. 有没有办法阻止这种行为。

Thanks in advance. 提前致谢。

Finally, found the answer. 最后找到答案。

Edit configuration in /node_modules/laravel-elixir/dist/Config.js /node_modules/laravel-elixir/dist/Config.js编辑配置

Lines 283 - 300: 283-300行:

    /*
 |----------------------------------------------------------------
 | UglifyJS Parser/Compressor/Beautifier
 |----------------------------------------------------------------
 |
 | UglifyJS is a JavaScript parser/compressor/beautifier.
 | It'll minify your JavaScript with ease and has an option to
 | mangle your code.
 |
 */

  uglify: {
    options: {
      compress: {
        drop_console: Elixir.inProduction
      }
    }
  }


To stop the removal of unused functions add unused: false to the compress options. 要停止删除未使用的功能,请在compress选项中添加unused: false

Change to: 改成:

    /*
 |----------------------------------------------------------------
 | UglifyJS Parser/Compressor/Beautifier
 |----------------------------------------------------------------
 |
 | UglifyJS is a JavaScript parser/compressor/beautifier.
 | It'll minify your JavaScript with ease and has an option to
 | mangle your code.
 |
 */

uglify: {
  options: {
    compress: {
      drop_console: Elixir.inProduction,
      unused: false
    }
  }
}


For more information on available options go to the UglifyJS Documentation . 有关可用选项的更多信息,请访问UglifyJS文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM