3

アセット パイプラインを使用して 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 に答える