fix js compression. Speed up static asset loading
This commit is contained in:
parent
8bc6714eb1
commit
ba7754e7a7
5 changed files with 32 additions and 29 deletions
|
@ -48,9 +48,10 @@ class Middleman::Server
|
|||
set :root, Dir.pwd
|
||||
end
|
||||
|
||||
require 'shotgun'
|
||||
config = File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'config.ru')
|
||||
app = Shotgun.new(config, &lambda { |inner_app| Middleman::Server })
|
||||
# require 'shotgun'
|
||||
# config = File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'config.ru')
|
||||
# app = Shotgun.new(config, &lambda { |inner_app| Middleman::Server })
|
||||
app = Middleman::Server.new
|
||||
|
||||
require 'rubygems'
|
||||
require 'thin'
|
||||
|
|
|
@ -29,7 +29,6 @@ module Middleman
|
|||
|
||||
def initialize(*args)
|
||||
Middleman::Server.new
|
||||
::Tilt.mappings.keys << "js"
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -41,11 +40,11 @@ module Middleman
|
|||
end
|
||||
|
||||
def build_static_files
|
||||
action Directory.new(self, Middleman::Server.public, Middleman::Server.build_dir)
|
||||
action Directory.new(self, Middleman::Server.public, Middleman::Server.build_dir, { :force => true })
|
||||
end
|
||||
|
||||
def build_dynamic_files
|
||||
action Directory.new(self, Middleman::Server.views, Middleman::Server.build_dir)
|
||||
action Directory.new(self, Middleman::Server.views, Middleman::Server.build_dir, { :force => true })
|
||||
end
|
||||
|
||||
@@hooks = {}
|
||||
|
@ -78,30 +77,29 @@ module Middleman
|
|||
execute!
|
||||
end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
def execute!
|
||||
lookup = config[:recursive] ? File.join(source, '**') : source
|
||||
lookup = File.join(lookup, '{*,.[a-z]*}')
|
||||
def execute!
|
||||
lookup = config[:recursive] ? File.join(source, '**') : source
|
||||
lookup = File.join(lookup, '{*,.[a-z]*}')
|
||||
|
||||
Dir[lookup].sort.each do |file_source|
|
||||
next if File.directory?(file_source)
|
||||
next if file_source.include?('layout')
|
||||
next unless file_source.split('/').select { |p| p[0,1] == '_' }.empty?
|
||||
|
||||
Dir[lookup].sort.each do |file_source|
|
||||
next if File.directory?(file_source)
|
||||
next if file_source.include?('layout')
|
||||
next unless file_source.split('/').select { |p| p[0,1] == '_' }.empty?
|
||||
|
||||
file_extension = File.extname(file_source)
|
||||
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
|
||||
file_destination.gsub!('/./', '/')
|
||||
|
||||
handled_by_tilt = ::Tilt.mappings.keys.include?(file_extension.gsub(/^\./, ""))
|
||||
if handled_by_tilt
|
||||
file_destination.gsub!(file_extension, "")
|
||||
destination = base.tilt_template(file_source, file_destination, config, &@block)
|
||||
else
|
||||
destination = base.copy_file(file_source, file_destination, config, &@block)
|
||||
end
|
||||
file_extension = File.extname(file_source)
|
||||
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
|
||||
file_destination.gsub!('/./', '/')
|
||||
|
||||
handled_by_tilt = ::Tilt.mappings.keys.include?(file_extension.gsub(/^\./, ""))
|
||||
if handled_by_tilt || (file_extension == ".js")
|
||||
file_destination.gsub!(file_extension, "") unless file_extension == ".js"
|
||||
destination = base.tilt_template(file_source, file_destination, config, &@block)
|
||||
else
|
||||
destination = base.copy_file(file_source, file_destination, config, &@block)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,9 @@
|
|||
module Middleman::Features::MinifyJavascript
|
||||
class << self
|
||||
def registered(app)
|
||||
# Only do minification on build or prod mode
|
||||
return unless [:build, :production].include? app.environment
|
||||
|
||||
Middleman::Features::MinifyJavascript::Haml::Javascript.send :include, ::Haml::Filters::Base
|
||||
|
||||
require "middleman/features/minify_javascript/rack"
|
||||
|
|
|
@ -161,7 +161,8 @@ class Middleman::Server
|
|||
set :app_file, File.expand_path(local_config)
|
||||
end
|
||||
|
||||
use ::Rack::ConditionalGet if environment == :development
|
||||
use ::Rack::ConditionalGet
|
||||
use ::Rack::Static, :urls => ["/#{self.images_dir}"], :root => "public"
|
||||
|
||||
@@run_after_features.each { |block| class_eval(&block) }
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module Middleman
|
||||
VERSION = "1.1.0.beta.3"
|
||||
VERSION = "1.1.0.beta.4"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue