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