Created
May 18, 2015 16:35
-
-
Save darkleaf/5cbbc8a300b7524bbbe7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Browserify | |
mattr_accessor(:base_dir) { "app/assets/browserify" } | |
# mattr_accessor(:transform) { 'babelify' } | |
mattr_accessor(:command) { '$(npm bin)/browserifyinc' } | |
class << self | |
def inline_bundle(context, entry: nil, require: nil, external: nil, transform: nil, source_map: true) | |
p 'inline_bundle' | |
p entry | |
opts = browserify_opts(entry, require, external, transform, source_map) | |
deps = bundle_deps(entry) | |
deps.each{ |d| context.depend_on d } | |
puts "#{command} #{opts}" | |
`#{command} #{opts}` | |
end | |
private | |
def browserify_opts(entry, require, external, transform, source_map) | |
opts = [] | |
opts << Array.wrap(transform).map { |i| "-t #{i}" } | |
opts << Array.wrap(entry).map { |i| "-e #{base_dir}/#{i}" } | |
opts << Array.wrap(require).map { |i| "-r #{i}" } | |
opts << Array.wrap(external).map { |i| "-x #{i}" } | |
opts << "--fast" | |
opts << "--full-paths" | |
opts << "--cachefile tmp/cache/browserify-cache.json" | |
opts << "--debug" if source_map && Rails.env.development? | |
opts.join(' ') | |
end | |
def bundle_deps(entry) | |
deps = [] | |
deps << __FILE__ | |
return deps if entry.blank? | |
deps += Dir[Rails.root.join('app/assets/browserify/**/*')] | |
deps | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment