我正在使用Asset Pipeline构建一些JavaScript,并将这些JavaScript移交给许多第三方开发人员。我想在生成的(可能是混淆的)输出文件的顶部放置警告注释,但尚不清楚如何使用链轮/ 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)
JetBrains的工具集具有一个“版权”插件https://plugins.jetbrains.com/plugin/88-copyright/
它可以将您的版权/标题注入源文件。我已经为IntelliJ Idea和RubyMine尝试过它,并且对我有用。
此插件可能会应用于整个项目,目录或最近更改的文件。