uglifier_with_source_maps 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 91aa8372e0ce1c8f331915f03fa4332451732da4
4
+ data.tar.gz: c434b34599b08016dc3af3c3ff5d52def1b8abc5
5
+ SHA512:
6
+ metadata.gz: 1c9b7521c15304088ac3d1762c15fcf5a14474009063a48902c74090bd2e3452cdb87a2b53d41664ea027cec6cbcb18cbe9c772e76bdd0f397caa1a30a9dbaf1
7
+ data.tar.gz: 2a5851657f24277e75226a0353064e4a2002136a884814d77dafcca6e18b0bf34df4003aab71432f3f46015715a0e8cf20bc4cd436c3c95ac561fdc84c8f283c
@@ -0,0 +1,52 @@
1
+ #General gem ignore paths
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
24
+
25
+ # OS X
26
+ .DS_Store
27
+ .AppleDouble
28
+ .LSOverride
29
+ Icon
30
+ # Thumbnails
31
+ ._*
32
+ # Files that might appear on external disk
33
+ .Spotlight-V100
34
+ .Trashes
35
+
36
+ # Windows
37
+ # Windows image file caches
38
+ Thumbs.db
39
+ ehthumbs.db
40
+ # Folder config file
41
+ Desktop.ini
42
+ # Recycle Bin used on file shares
43
+ $RECYCLE.BIN/
44
+
45
+
46
+ # Sublime
47
+ # SublimeText workspace
48
+ *.sublime-workspace
49
+
50
+ #oh my zsh plugin file
51
+ .rake_tasks
52
+ .cap_tasks*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in uglifier_with_source_maps.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Leif Ringstad
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ # UglifierWithSourceMaps
2
+
3
+ Create sourcemaps when compressing assets in your Rails 3.2 applications.
4
+
5
+ This gem uses Uglifier to create sourcemaps for your concatenated javascripts in Rails 3.2.x. It is meant to use as a replacement javascript compressor.
6
+
7
+ _Note: This gem is for Rails 3.2.x_
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'uglifier_with_source_maps'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install uglifier_with_source_maps
22
+
23
+ ## Usage
24
+
25
+ In your rails applications environment configuration add this:
26
+
27
+ ```
28
+ config.assets.js_compressor = :uglifier_with_source_maps
29
+ ```
30
+
31
+ If you need to pass options to uglifier:
32
+
33
+ ```
34
+ config.assets.js_compressor = UglifierWithSourceMaps::Compressor.new({
35
+ output: {
36
+ beautify: true, indent_level: 2, comments: :none
37
+ }
38
+ })
39
+ ```
40
+
41
+ Your assets will be built as normal, and maps concatenated sources will be provided as well in asset\_path/maps and asset\_path/sources
42
+
43
+ Example
44
+ rake assets:precompile
45
+
46
+ ```
47
+ # application.js
48
+ rake assets:precompile
49
+
50
+ # -> public/assets/application-ab258eecc169e5febb9da42389481bff.js
51
+ # -> public/assets/maps/application-ab258eecc169e5febb9da42389481bff.map
52
+ # -> public/assets/sources/application-ab258eecc169e5febb9da42389481bff.js
53
+
54
+ ```
55
+
56
+ ## Dependencies
57
+ * uglifier >= 2.5
58
+ * sprockets ~> 2.2.2
59
+ * actionpack ~> 3.2.19
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it ( https://github.com/[my-github-username]/uglifier_with_source_maps/fork )
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,19 @@
1
+ require 'sprockets/railtie'
2
+ require 'uglifier'
3
+ require "uglifier_with_source_maps/version"
4
+ require "uglifier_with_source_maps/compressor"
5
+
6
+ module Sprockets
7
+ # Processing
8
+ autoload :Processing, "sprockets/processing"
9
+ end
10
+
11
+ require 'sprockets'
12
+ Dir[File.expand_path('../uglifier_with_source_maps/sprockets/*.rb', __FILE__)].each do |f|
13
+ require f
14
+ end
15
+ require 'uglifier_with_source_maps/actionpack/lib/sprockets/compressors'
16
+
17
+ require 'uglifier_with_source_maps/railtie'
18
+
19
+
@@ -0,0 +1,15 @@
1
+ module Sprockets
2
+ module Compressors
3
+ register_js_compressor(:uglify_with_source_maps, 'UglifierWithSourceMaps::Compressor', require: "uglifier_with_source_maps")
4
+ register_js_compressor(:uglifier_with_source_maps, 'UglifierWithSourceMaps::Compressor', require: "uglifier_with_source_maps")
5
+ end
6
+ class LazyCompressor #:nodoc:
7
+ def compress(data, context = nil)
8
+ if compressor.instance_of?(UglifierWithSourceMaps::Compressor)
9
+ compressor.compress(data, context)
10
+ else
11
+ compressor.compress(data)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ module UglifierWithSourceMaps
2
+ class Compressor
3
+ def self.call(*args)
4
+ new.call(*args)
5
+ end
6
+
7
+ def initialize(options = {})
8
+ @uglifier = Uglifier.new(options)
9
+ # @cache_key = [
10
+ # 'UglifierWithSourceMapsCompressor',
11
+ # ::Uglifier::VERSION,
12
+ # ::UglifierWithSourceMaps::VERSION,
13
+ # options
14
+ # ]
15
+ end
16
+
17
+ def compress(data, context)
18
+
19
+ minified_data, sourcemap = @uglifier.compile_with_map(data)
20
+
21
+ # write source map
22
+ minified_filename = [Rails.application.config.assets.prefix, "#{context.logical_path}-#{digest(minified_data)}.js"].join('/')
23
+ sourcemap_filename = [Rails.application.config.assets.prefix, Rails.application.config.assets.sourcemaps_prefix, "#{context.logical_path}-#{digest(minified_data)}.map"].join('/')
24
+ concatenated_filename = [Rails.application.config.assets.prefix, Rails.application.config.assets.uncompressed_prefix, "#{context.logical_path}-#{digest(minified_data)}.js"].join('/')
25
+
26
+ map = JSON.parse(sourcemap)
27
+ map['file'] = minified_filename
28
+ map['sources'] = [concatenated_filename]
29
+
30
+ FileUtils.mkdir_p File.dirname(File.join(Rails.public_path, sourcemap_filename))
31
+ FileUtils.mkdir_p File.dirname(File.join(Rails.public_path, concatenated_filename))
32
+
33
+ # Write sourcemap and uncompressed js
34
+ File.open(File.join(Rails.public_path, sourcemap_filename), "w") { |f| f.puts map.to_json }
35
+ File.open(File.join(Rails.public_path, concatenated_filename), "w") {|f| f.write(data)}
36
+
37
+ sourcemap_comment = "\n//# sourceMappingURL=#{sourcemap_filename}\n"
38
+
39
+ return minified_data + sourcemap_comment
40
+ end
41
+
42
+ def digest(io)
43
+ Rails.application.assets.digest.update(io).hexdigest
44
+ end
45
+ end
46
+ end
47
+
48
+
49
+
50
+
51
+
@@ -0,0 +1,25 @@
1
+ require "action_controller/railtie"
2
+
3
+ module Sprockets
4
+ autoload :Processing, "sprockets/processing"
5
+ end
6
+
7
+ module UglifierWithSourceMaps
8
+ class Railtie < ::Rails::Railtie
9
+
10
+ initializer "uglifier-with-source-maps.environment", :after => "sprockets.environment", :group => :all do |app|
11
+ config = app.config
12
+ config.assets.sourcemaps_prefix = "maps"
13
+ config.assets.uncompressed_prefix = "sources"
14
+
15
+ # manifest_dir = config.assets.manifest || File.join(Rails.public_path, config.assets.prefix)
16
+ # digests_manifest = File.join(manifest_dir, "manifest.yml")
17
+ # sources_manifest = File.join(manifest_dir, "sources_manifest.yml")
18
+ # config.assets.digests = (File.exist?(digests_manifest) && YAML.load_file(digests_manifest)) || {}
19
+ # config.assets.source_digests = (File.exist?(sources_manifest) && YAML.load_file(sources_manifest)) || {}
20
+
21
+ # # Clear digests if loading previous manifest format
22
+ # config.assets.digests = {} if config.assets.digests[:digest_files]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'sprockets/processing'
3
+ rescue LoadError
4
+ end
5
+ module Sprockets
6
+ # `Processing` is an internal mixin whose public methods are exposed on
7
+ # the `Environment` and `Index` classes.
8
+ module Processing
9
+
10
+ # Assign a compressor to run on `application/javascript` assets.
11
+ #
12
+ # The compressor object must respond to `compress` or `compile`.
13
+ def js_compressor=(compressor)
14
+ expire_index!
15
+ unregister_bundle_processor 'application/javascript', :js_compressor
16
+ return unless compressor
17
+
18
+ register_bundle_processor 'application/javascript', :js_compressor do |context, data|
19
+ compressor.compress(data, context)
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module UglifierWithSourceMaps
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'uglifier_with_source_maps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "uglifier_with_source_maps"
8
+ spec.version = UglifierWithSourceMaps::VERSION
9
+ spec.authors = ["Leif Ringstad"]
10
+ spec.email = ["leifcr@gmail.com"]
11
+ spec.summary = %q{Create js sourcemaps on your Rails 3.2 applications}
12
+ spec.description = %q{UglifierWithSourceMaps overrides parts of sprockets to create sourcemaps using uglifier for your javascript assets. It is meant to be used in production.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "sprockets", "~> 2.2.2"
22
+ spec.add_runtime_dependency "actionpack", "~> 3.2.19"
23
+ spec.add_runtime_dependency "uglifier", ">= 2.5.0"
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uglifier_with_source_maps
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Leif Ringstad
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sprockets
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.19
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.19
41
+ - !ruby/object:Gem::Dependency
42
+ name: uglifier
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.5.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: UglifierWithSourceMaps overrides parts of sprockets to create sourcemaps
84
+ using uglifier for your javascript assets. It is meant to be used in production.
85
+ email:
86
+ - leifcr@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/uglifier_with_source_maps.rb
97
+ - lib/uglifier_with_source_maps/actionpack/lib/sprockets/compressors.rb
98
+ - lib/uglifier_with_source_maps/compressor.rb
99
+ - lib/uglifier_with_source_maps/railtie.rb
100
+ - lib/uglifier_with_source_maps/sprockets/processing.rb
101
+ - lib/uglifier_with_source_maps/version.rb
102
+ - uglifier_with_source_maps.gemspec
103
+ homepage: ''
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Create js sourcemaps on your Rails 3.2 applications
127
+ test_files: []