diff --git a/middleman-core/features/asset_hash.feature b/middleman-core/features/asset_hash.feature
index 3098e73c..dd659336 100644
--- a/middleman-core/features/asset_hash.feature
+++ b/middleman-core/features/asset_hash.feature
@@ -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"
diff --git a/middleman-core/fixtures/asset-hash-source-map/config.rb b/middleman-core/fixtures/asset-hash-source-map/config.rb
new file mode 100644
index 00000000..1327d8f0
--- /dev/null
+++ b/middleman-core/fixtures/asset-hash-source-map/config.rb
@@ -0,0 +1,6 @@
+
+activate :asset_hash
+
+activate :relative_assets
+
+activate :directory_indexes
diff --git a/middleman-core/fixtures/asset-hash-source-map/lib/middleware.rb b/middleman-core/fixtures/asset-hash-source-map/lib/middleware.rb
new file mode 100644
index 00000000..8ee825fd
--- /dev/null
+++ b/middleman-core/fixtures/asset-hash-source-map/lib/middleware.rb
@@ -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
diff --git a/middleman-core/fixtures/asset-hash-source-map/source/index.html.erb b/middleman-core/fixtures/asset-hash-source-map/source/index.html.erb
new file mode 100644
index 00000000..a88cc13f
--- /dev/null
+++ b/middleman-core/fixtures/asset-hash-source-map/source/index.html.erb
@@ -0,0 +1,6 @@
+<% content_for :head do %>
+
The Middleman!
+<% end %>
+
+Testing the sitemap hashing
+
diff --git a/middleman-core/fixtures/asset-hash-source-map/source/javascripts/application.js b/middleman-core/fixtures/asset-hash-source-map/source/javascripts/application.js
new file mode 100644
index 00000000..c72f8572
--- /dev/null
+++ b/middleman-core/fixtures/asset-hash-source-map/source/javascripts/application.js
@@ -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
diff --git a/middleman-core/fixtures/asset-hash-source-map/source/javascripts/application.js.map b/middleman-core/fixtures/asset-hash-source-map/source/javascripts/application.js.map
new file mode 100644
index 00000000..6a5acd5c
--- /dev/null
+++ b/middleman-core/fixtures/asset-hash-source-map/source/javascripts/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"}
\ No newline at end of file
diff --git a/middleman-core/fixtures/asset-hash-source-map/source/layout.erb b/middleman-core/fixtures/asset-hash-source-map/source/layout.erb
new file mode 100644
index 00000000..c8aacecf
--- /dev/null
+++ b/middleman-core/fixtures/asset-hash-source-map/source/layout.erb
@@ -0,0 +1,17 @@
+
+
+
+
+
+ <%= javascript_include_tag "application" %>
+ <%= yield_content :head %>
+
+
+
+
+
+ <%= yield %>
+
+
+
+
diff --git a/middleman-core/lib/middleman-core/extensions/asset_hash.rb b/middleman-core/lib/middleman-core/extensions/asset_hash.rb
index c90d0223..247d1160 100644
--- a/middleman-core/lib/middleman-core/extensions/asset_hash.rb
+++ b/middleman-core/lib/middleman-core/extensions/asset_hash.rb
@@ -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'
diff --git a/middleman-core/lib/middleman-core/util/rack.rb b/middleman-core/lib/middleman-core/util/rack.rb
index 8399b3af..17ac7252 100644
--- a/middleman-core/lib/middleman-core/util/rack.rb
+++ b/middleman-core/lib/middleman-core/util/rack.rb
@@ -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('