每个文件选择的Rails 3.2资产管道COM pression [英] Selective Rails 3.2 asset pipeline compression per file

查看:123
本文介绍了每个文件选择的Rails 3.2资产管道COM pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择COM preSS一些在Rails 3.2的应用程序的JavaScript文件,但仍然有所有的JS资产在生产环境中的单个文件捆绑服务。

I'd like to selectively compress some of the javascript files in a Rails 3.2 app, but still have all js assets served from a single bundled file in the production environment.

语法这样,应用程序/资产/ Java脚本/ application.js中文件里,使用编造 :COM preSS =>假选项传递到最后3链轮要求指令,我希望解释我想要达到的。

Syntax like this, inside of the app/assets/javascripts/application.js file, using the made-up :compress => false option passed to the last 3 sprockets require directives I hope explains what I'm trying to achieve.

// Contents of app/assets/javascripts/application.js
//
//= require jquery
//= require jquery_ujs
//= require angular-1.0.1/angular, :compress => false
//= require angular-1.0.1/angular-resource, :compress => false
//= require products, :compress => false

所以的jquery.js和jquery_ujs.js文件将COM pressed(由Rails的资产编译,它默认使用UglifierJS),剩下的3个文件将不COM pressed,但他们会捆绑成束的application.js。

So jquery.js and jquery_ujs.js files will be compressed (by Rails asset compilation, which uses UglifierJS by default), and the remaining 3 files will not be compressed, but they will be bundled into the application.js bundle.

是否有任何可用的方式做到这一点?

Is there any way available to do this?

的动机是,products.js文件包含angularjs控制器,利用角的依赖注入的需要特定的变量名称,如 $范围 $ HTTP 不会改变。

The motivation is that the products.js file contains an angularjs controller that makes use of angular's dependency injection which requires specific variable names such as $scope and $http are not altered.

推荐答案

我用这条线在我的配置/环境/ production.rb 文件

config.assets.js_com pressor ​​=链轮:: LazyCom $ P $ {pssor.new Uglifier.new(:轧=>假)}

据COM preSS我的控制器,但它不会改变方法签名,所以DI仍正常工作。

It compress my controllers but it doesn't change method signatures so DI still works as expected.

这篇关于每个文件选择的Rails 3.2资产管道COM pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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