gpt4 book ai didi

ruby-on-rails-3.1 - 如何将样板注释或许可证添加到使用 Rails 3.1 Asset Pipeline 编译的 JavaScript 文件的顶部?

转载 作者:行者123 更新时间:2023-12-02 02:21:40 24 4
gpt4 key购买 nike

我正在使用 Asset Pipeline 构建一些 JavaScript,这些 JavaScript 将移交给许多第三方开发人员。我想在生成的(可能是混淆的)输出文件的顶部放置一条警告注释,但不清楚如何使用 sprockets/coffeescript 组合实现这一点。

# This is a manifest file that'll be compiled into including all the files listed below.
# Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
# be included in the compiled file accessible from http://example.com/assets/application.js
# It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
# the compiled file.
###
The following code was compiled from source by MF.
Please do not edit this JavaScript directly.
####
#= require util/extensions
#= require util/date_manipulation
#= require util/format
#= require points_data
#= require graphics/canvas_graphics
#= require graphics/explorer_canvas_graphics
#= require renderer

我得到以下结果:

(function() {
/*
The following code was compiled from source by MF.
Please do not edit this JavaScript directly.
*/
}).call(this);

我想要的是这个(或类似的东西):

/*
The following code was compiled from source by MF.
Please do not edit this JavaScript directly.
*/
(function() {
// ******** my compiled code from all those required files! *******
}).call(this);

我怎样才能让它发挥作用?

最佳答案

最简单的方法是在编译后向文件添加注释。

Rails 的默认压缩器 - Uglifier - 有一个 :copyright 选项用于保留文件的第一行注释,因此您可以使用它来保留注释(和所有其他版权)。


config.assets.js_compressor = Uglifier.new(:copyright => true)

关于ruby-on-rails-3.1 - 如何将样板注释或许可证添加到使用 Rails 3.1 Asset Pipeline 编译的 JavaScript 文件的顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7892939/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com