update minify js extension
This commit is contained in:
parent
11a3507528
commit
1c4e6cb835
|
@ -59,10 +59,8 @@ module Middleman
|
|||
Middleman::Extensions::MinifyCss.register
|
||||
|
||||
# MinifyJavascript compresses JS
|
||||
Middleman::Extensions.register(:minify_javascript) do
|
||||
require "middleman-more/extensions/minify_javascript"
|
||||
Middleman::Extensions::MinifyJavascript
|
||||
end
|
||||
Middleman::Extensions::MinifyJavascript.register
|
||||
|
||||
# RelativeAssets allow any asset path in dynamic templates to be either
|
||||
# relative to the root of the project or use an absolute URL.
|
||||
|
|
|
@ -1,34 +1,25 @@
|
|||
# Extension namespace
|
||||
module Middleman
|
||||
module Extensions
|
||||
|
||||
# Minify Javascript Extension
|
||||
module MinifyJavascript
|
||||
class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
|
||||
option :compressor, nil, 'Set the JS compressor to use.'
|
||||
option :inline, false, 'Whether to minify JS inline within HTML files'
|
||||
option :ignore, [], 'Patterns to avoid minifying'
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
# Once registered
|
||||
def registered(app, options={})
|
||||
app.config.define_setting :js_compressor, nil, 'Set the JS compressor to use. Deprecated in favor of the :compressor option when activating :minify_js'
|
||||
end
|
||||
|
||||
ignore = Array(options[:ignore]) << /\.min\./
|
||||
inline = options[:inline] || false
|
||||
|
||||
# Once config is parsed
|
||||
app.after_configuration do
|
||||
chosen_compressor = js_compressor || options[:compressor] || begin
|
||||
def after_configuration
|
||||
chosen_compressor = app.config[:js_compressor] || options[:compressor] || begin
|
||||
require 'uglifier'
|
||||
::Uglifier.new
|
||||
end
|
||||
|
||||
# Setup Rack middlware to minify JS
|
||||
use Rack, :compressor => chosen_compressor,
|
||||
:ignore => ignore,
|
||||
:inline => inline
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
# Setup Rack middleware to minify CSS
|
||||
app.use Rack, :compressor => chosen_compressor,
|
||||
:ignore => options[:ignore] + [/\.min\./],
|
||||
:inline => options[:inline]
|
||||
end
|
||||
|
||||
# Rack middleware to look for JS and compress it
|
||||
|
@ -90,5 +81,3 @@ module Middleman
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue