Javascript是否未预编译? [英] Javascripts not precompiled?

查看:74
本文介绍了Javascript是否未预编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的app/assets/javascripts/specific.js中有

//= require_tree ./specific

app/assets/javascripts/specific/chat中我有pusher.js

另外,在config/environments/production中我有

config.assets.precompile += %w( specific.js some_other_manifest.js )

但是,当我投入生产(在heroku上)时,它仍然抱怨pusher.js没有被预编译.我在这里做什么错了?

However, when I go into production (on heroku) it still complains pusher.js is not precompiled. What am I doing wrong here?

在部署应用程序时,javascript文件似乎已编译.

While the application is deployed, the javascript files seem to be compiled.

来自Heroku日志:

from Heroku logs:

   Compiled specific/chat/pusher.js  (0ms)  (pid 1042)
   Compiled specific.js  (60ms)  (pid 1042)

但是当我去查看时,

 ActionView::Template::Error (specific/chat/pusher.js isn't precompiled):
     1: <%= javascript_include_tag 'specific/chat/pusher' %>
     2: <%= javascript_include_tag params[:controller] %>
     3: 
     4: <div id="chat-header">
   app/views/messages/index.html.erb:1:in `_app_views_messages_index_html_erb___3285714722884343394_70246542189040'

我还尝试将config.assets.precompile ..选项放在config/application.rb而不是production.rb

I also tried putting config.assets.precompile .. option inside config/application.rb instead of production.rb

相关:资产说未预编译"当它们被预编译时

当我运行assets:precompile并查看public/assets文件夹时,我看到它们都是预编译的(例如specific-bfgbfbf4534535.js)

When I run assets:precompile and look in public/assets folder, I see that they are all precompiled (e.g. specific-bfgbfbf4534535.js)

因此该资产实际上是预编译的,但错误表明它没有预编译

在我看来:

<%= javascript_include_tag 'specific/chat/pusher.js' %>

推荐答案

您不包含特定文件,而是包含整个清单,这就是清单的全部内容.

You don't include specific files, you include the entire manifest, that's the whole point of manifests.

这行不通:

<%= javascript_include_tag 'specific/chat/pusher' %>

相反,您需要为顶层清单提供单个include:

Instead, you need a single include for the top-level manifest:

<%= javascript_include_tag 'specifics' %>

在您的问题下方的评论中:

From your comment below your question:

不应将其包含在application.html.erb

It's not supposed to be included in application.html.erb

这不是预编译资产的工作方式.您需要包括specifics.js,或构建另一个(更详细的)清单.清单的要点是,它们会产生一个要包含的单个最小化的代码块.您具体说您在已编译资产文件夹中看到一个specific-bfgbfbf4534535.js那个是将要包含的文件,并且包含pusher.js.

That isn't how precompiled assets work. You need to include specifics.js, or build another (more granular) manifest. The point of manifests is that they produce a single minified blob of code to be included. You specifically say you see a specific-bfgbfbf4534535.js in your compiled assets folder; that is the file that will be included, and it contains pusher.js.

这篇关于Javascript是否未预编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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