3

我正在使用 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);

我要如何让它工作?

4

2 回答 2

2

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

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

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

于 2011-10-25T17:42:13.923 回答
0

JetBrains 的工具集有一个“版权”插件 https://plugins.jetbrains.com/plugin/88-copyright/

它允许将您的版权/标题注入源文件。我已经为 IntelliJ Idea 和 RubyMine 尝试过它,它对我有用。

该插件可能适用于整个项目、目录或最近更改的文件。

于 2020-01-15T10:28:39.143 回答