Merge pull request #1815 from adam-h/sourcemap-hashing
Add sourceMap comment to asset_hash and hash .map files by default
This commit is contained in:
commit
d776f07bfc
|
@ -285,3 +285,17 @@ Feature: Assets get file hashes appended to them and references to them are upda
|
|||
| javascripts/jquery.min-276c87ff.js |
|
||||
And the following files should not exist:
|
||||
| javascripts/jquery.min.js |
|
||||
|
||||
Scenario: Source map paths include the hash
|
||||
Given a successfully built app at "asset-hash-source-map"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| index.html |
|
||||
| javascripts/application-4553338c.js |
|
||||
| javascripts/application.js-22cc2b5f.map |
|
||||
| index.html |
|
||||
And the following files should not exist:
|
||||
| javascripts/application.js |
|
||||
| javascripts/application.js.map |
|
||||
|
||||
And the file "javascripts/application-4553338c.js" should contain "//# sourceMappingURL=application.js-22cc2b5f.map"
|
||||
|
|
6
middleman-core/fixtures/asset-hash-source-map/config.rb
Normal file
6
middleman-core/fixtures/asset-hash-source-map/config.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
activate :asset_hash
|
||||
|
||||
activate :relative_assets
|
||||
|
||||
activate :directory_indexes
|
|
@ -0,0 +1,16 @@
|
|||
class Middleware
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
status, headers, response = @app.call(env)
|
||||
body = ''
|
||||
response.each {|part| body += part }
|
||||
if (env["PATH_INFO"] =~ /css$/)
|
||||
body += "\n/* Added by Rack filter */"
|
||||
status, headers, response = Rack::Response.new(body, status, headers).finish
|
||||
end
|
||||
[status, headers, response]
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
<% content_for :head do %>
|
||||
<title>The Middleman!</title>
|
||||
<% end %>
|
||||
|
||||
<h1>Testing the sitemap hashing</h1>
|
||||
<br /><br /><br />
|
|
@ -0,0 +1,2 @@
|
|||
function foo(){var message="HEY THERE FRIEND!";var para=document.createElement("p");para.innerHTML=message;var body=document.getElementsByTagName("body")[0];body.insertBefore(para,body.firstChild)}window.onload=foo;
|
||||
//# sourceMappingURL=application.js.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["source/javascripts/application.js"],"names":["foo","message","para","document","createElement","innerHTML","body","getElementsByTagName","insertBefore","firstChild","window","onload"],"mappings":"AAAA,QAASA,OACP,GAAIC,SAAU,mBACd,IAAIC,MAAOC,SAASC,cAAc,IAClCF,MAAKG,UAAYJ,OACb,IAAIK,MAAOH,SAASI,qBAAqB,QAAQ,EAC/CD,MAAKE,aAAaN,KAAMI,KAAKG,YAGpCC,OAAOC,OAASX"}
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<%= javascript_include_tag "application" %>
|
||||
<%= yield_content :head %>
|
||||
</head>
|
||||
|
||||
<body class="<%= page_classes %>">
|
||||
|
||||
<div id="main" role="main">
|
||||
<%= yield %>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -3,7 +3,7 @@ require 'middleman-core/rack'
|
|||
|
||||
class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
||||
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for hashable assets.'
|
||||
option :exts, %w(.jpg .jpeg .png .gif .webp .js .css .otf .woff .woff2 .eot .ttf .svg .svgz), 'List of extensions that get asset hashes appended to them.'
|
||||
option :exts, %w(.jpg .jpeg .png .gif .webp .js .css .otf .woff .woff2 .eot .ttf .svg .svgz .map), 'List of extensions that get asset hashes appended to them.'
|
||||
option :ignore, [], 'Regexes of filenames to skip adding asset hashes to'
|
||||
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ module Middleman
|
|||
|
||||
Contract String, String, ArrayOf[String], Proc => String
|
||||
def rewrite_paths(body, _path, exts, &_block)
|
||||
matcher = /([\'\"\(,]\s*)([^\s\'\"\)>]+(#{::Regexp.union(exts)}))/
|
||||
matcher = /([\'\"\(,]\s*|# sourceMappingURL=)([^\s\'\"\)>]+(#{::Regexp.union(exts)}))/
|
||||
|
||||
url_fn_prefix = 'url('
|
||||
|
||||
|
|
Loading…
Reference in a new issue