sprockets_uglifier_with_source_maps 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34c63d7b1b496c7e21bd25a56758015f1fb85355
4
- data.tar.gz: 296b7ddcc6c47fe5b71d60f9a221dd578bf82db8
3
+ metadata.gz: 3de26fb885769b727d3482302529e5387b87f2cb
4
+ data.tar.gz: 05e46c1acfe11a7c7da62df1c221373b12a661c2
5
5
  SHA512:
6
- metadata.gz: 523486d7ce11717c4c6411c1f1f82749d5cc70290783eafeddc45326220710787d9b06addb247f77458333f00a9c08390b552ad7fb458fbccd2ed9172cd93cd1
7
- data.tar.gz: fc866ff60cbf78b6dbfbabf6dd9f7497f57bae94f8baf5febd88acc14462509bf1adc3a7f9347cb150bf7764c87f8cff38d33831431b6ddd072b6a19b62eeeac
6
+ metadata.gz: 6c5c1418015b92e5725cf1268dc0b31dc10cd454d7f7fecf1d97e2525e3d4cc727b70dac990c852d281e8d7c0607d0edee85296e06bc9f03d2165726a6fc7a1f
7
+ data.tar.gz: 5735157d5a94f232900da0cbc1414c2a5ba362b608b2fe81928824ebd1353aedc1d443b0722c92eab9f205a1761dd6dc33fb35f051e023e35b9fa1033d5f62ab
data/README.md CHANGED
@@ -8,6 +8,7 @@ It is meant to be used as a replacement for javascript compressor.
8
8
  Source maps are useful for debugging javascript and many errors monitoring services utilize them,
9
9
  for example [Rollbar](https://rollbar.com/docs/source-maps/).
10
10
 
11
+ For Rails 3.2 see: https://github.com/leifcr/uglifier_with_source_maps
11
12
 
12
13
  ## Installation
13
14
 
@@ -32,7 +33,7 @@ In your Rails applications environment configuration:
32
33
 
33
34
  If you need to pass options to uglifier:
34
35
 
35
- config.assets.uglifier = {output: {beautify: true, indent_level: 2}, compress: {angular: true}}
36
+ config.assets.uglifier = {output: {beautify: true, indent_level: 2}, compress: {angular: true}}
36
37
 
37
38
  Your assets will be built as normal, also maps and concatenated sources will be provided as well in `public/assets/maps` and `public/assets/sources`.
38
39
  These subdirs may be configured:
@@ -40,6 +41,20 @@ These subdirs may be configured:
40
41
  config.assets.sourcemaps_prefix = 'my_maps'
41
42
  config.assets.uncompressed_prefix = 'my_sources'
42
43
 
44
+ You can optionally gzip your maps and sources as well (since these files live outside of the assets pipeline this won't happen automatically):
45
+
46
+ config.assets.sourcemaps_gzip = true
47
+
48
+ By default maps and sources are defined relatively and will be fetched from the same domain your js file is served from. If you are using a CDN you may not want this - instead you might want to use a direct link to your site so you can more easily implement IP or Basic Auth protection:
49
+
50
+ # set to a url - js will be served from 'http://cdn.host.com' but source map links will use 'http://some.host.com/'
51
+
52
+ config.assets.sourcemaps_url_root = 'http://some.host.com/'
53
+
54
+ If you use CloudFront you might want to generate a signed url for these files that limits access based on IP address. You can do that by setting sourcemaps_url_root to a Proc and handling your URL signing there:
55
+
56
+ # using a Proc - see the AWS SDK docs for everything required to make this work
57
+ config.assets.sourcemaps_url_root = Proc.new { |file| MyApp.generate_a_signed_url_for file }
43
58
 
44
59
  ## Example
45
60
 
@@ -6,10 +6,11 @@ module SprocketsUglifierWithSM
6
6
  compressed_data, sourcemap = Uglifier.new(options).compile_with_map(data)
7
7
 
8
8
  uncompressed_filename = File.join(Rails.application.config.assets.prefix, Rails.application.config.assets.uncompressed_prefix, "#{context.logical_path}-#{digest(data)}.js")
9
+ uncompressed_url = filename_to_url uncompressed_filename
9
10
 
10
11
  sourcemap = JSON.parse(sourcemap)
11
12
  sourcemap['file'] = "#{context.logical_path}.js"
12
- sourcemap['sources'] = [uncompressed_filename]
13
+ sourcemap['sources'] = [uncompressed_url]
13
14
  sourcemap = sourcemap.to_json
14
15
 
15
16
  sourcemap_filename = File.join(Rails.application.config.assets.prefix, Rails.application.config.assets.sourcemaps_prefix, "#{context.logical_path}-#{digest(sourcemap)}.js.map")
@@ -20,11 +21,34 @@ module SprocketsUglifierWithSM
20
21
  File.open(sourcemap_path, 'w') { |f| f.write sourcemap }
21
22
  File.open(uncompressed_path, 'w') { |f| f.write data }
22
23
 
23
- compressed_data.concat "\n//# sourceMappingURL=#{sourcemap_filename}\n"
24
+ if Rails.application.config.assets.sourcemaps_gzip
25
+ [sourcemap_path,uncompressed_path ].each do |f|
26
+ Zlib::GzipWriter.open("#{f}.gz") do |gz|
27
+ gz.mtime = File.mtime(f)
28
+ gz.orig_name = f
29
+ gz.write IO.binread(f)
30
+ end
31
+ end
32
+ end
33
+
34
+ sourcemap_url = filename_to_url sourcemap_filename
35
+ compressed_data.concat "\n//# sourceMappingURL=#{sourcemap_url}\n"
24
36
  end
25
37
 
26
38
  private
27
39
 
40
+ def filename_to_url(filename)
41
+ url_root = Rails.application.config.assets.sourcemaps_url_root
42
+ case url_root
43
+ when FalseClass
44
+ filename
45
+ when Proc
46
+ url_root.call filename
47
+ else
48
+ File.join url_root.to_s, filename
49
+ end
50
+ end
51
+
28
52
  def digest(io)
29
53
  Rails.application.assets.digest.update(io).hexdigest
30
54
  end
@@ -7,6 +7,8 @@ module SprocketsUglifierWithSM
7
7
  config = app.config
8
8
  config.assets.sourcemaps_prefix ||= 'maps'
9
9
  config.assets.uncompressed_prefix ||= 'sources'
10
+ config.assets.sourcemaps_gzip ||= false
11
+ config.assets.sourcemaps_url_root ||= false
10
12
  end
11
13
  end
12
14
  end
@@ -1,3 +1,3 @@
1
1
  module SprocketsUglifierWithSM
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ['alerticus@gmail.com']
10
10
  spec.summary = %q{Create javascript source maps for your Rails 4.2 applications}
11
11
  spec.description = %q{sprockets_uglifier_with_source_maps creates source maps for your javascript assets along with their compression using uglifier.}
12
- spec.homepage = 'https://github.com/AlexanderPavlenko/uglifier_with_source_maps'
12
+ spec.homepage = 'https://github.com/AlexanderPavlenko/sprockets_uglifier_with_source_maps'
13
13
  spec.license = 'MIT'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets_uglifier_with_source_maps
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Pavlenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2015-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets-rails
@@ -83,8 +83,8 @@ files:
83
83
  - lib/sprockets_uglifier_with_source_maps/compressor.rb
84
84
  - lib/sprockets_uglifier_with_source_maps/railtie.rb
85
85
  - lib/sprockets_uglifier_with_source_maps/version.rb
86
- - uglifier_with_source_maps.gemspec
87
- homepage: https://github.com/AlexanderPavlenko/uglifier_with_source_maps
86
+ - sprockets_uglifier_with_source_maps.gemspec
87
+ homepage: https://github.com/AlexanderPavlenko/sprockets_uglifier_with_source_maps
88
88
  licenses:
89
89
  - MIT
90
90
  metadata: {}
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.2.2
107
+ rubygems_version: 2.4.5
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Create javascript source maps for your Rails 4.2 applications