直接链接到资产管道中的已编译资源? [英] Link directly to compiled resource in asset pipeline?

查看:50
本文介绍了直接链接到资产管道中的已编译资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本上是用户嵌入的小部件"的脚本.

I have a script that's basically a "widget" that users embed.

它只有简单的原始javascript,对其他资源没有任何要求.它位于/app/assets/javascripts/delivery.js

It's got just simple vanilla javascript and doesn't have any require's to other resources. It's located at /app/assets/javascripts/delivery.js

我要做的是压缩/编译文件,然后让用户从脚本标签直接链接到该文件,即. <script src="http://example.com/assets/delivery.js"></script>

What I want to do is have the file get compressed/compiled and then let users link directly to it from a script tag, ie. <script src="http://example.com/assets/delivery.js"></script>

但是现在...这是行不通的.该文件在生产环境中不存在.

But right now...that's a no-go. That file doesn't exist in production.

那么,如何像在管道中其他任何JS文件一样压缩该文件,然后直接链接到该文件?

So, how can I compress that file like any other JS file in the pipeline, and then link directly to it?

推荐答案

如果添加

 config.assets.precompile += ['delivery.js']

到您的application.rb,然后delivery.js将被视为清单文件:它将被预编译并在生产中用作delivery.js.清单文件通常只是一系列//= require(或//= require_directory)语句,但是其中包含的任何javascript也会添加到生成的文件中.

to your application.rb, then delivery.js will be treated as a manifest file: it will be precompiled and served up as delivery.js in production. Manifest files are often just a series of //= require (or //= require_directory) statements, but any javascript they contain will also be added to the generated file.

默认情况下,application.js清单包含所有内容-您想对其进行调整,以使其不包含仅用于独立提供的javascript.

By default the application.js manifest includes everything - you way want to tweak this so that it doesn't include javascript which is intended only to be served standalone.

这篇关于直接链接到资产管道中的已编译资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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