6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

grunt-contrib-uglifyでsourceMapのファイル名を可変にする方法

Last updated at Posted at 2013-07-05

忘備録として。
ファイルをコンパクトにする際に使用するgrunt-contrib-uglify.
sourceMap オプションでファイル名を指定する場合、公式サイトでは固定ファイル名で出力しているが
実利用では可変ファイル名を扱う場合が多いので、その場合の設定方法を調べてみた。

sourceMap にはfunctionも指定できるので、これによってファイル名を可変にできる。

Gruntfile.js
    uglify: {
      options: {
          sourceMap: function(name) { return name.replace(/.js/,".map");} 
      },
      build: {
		files: [
				{
				  expand: true,
				  src: ['**/*.js'], 
				  dest: '../build/',
				  ext: '.js',  
				},
			  ],
	  }
    },

2017/04 追記
記事投稿後、sourceMap まわりのオプションが整理・追加されて、いろいろ変わったようです。
動作確認はしていませんが、 sourceMap ではなく sourceMapName のオプション名で同様のことができそうです。詳しくは公式ページを見てください。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?