lib/sewing_kit/webpack/helper.rb in sewing_kit-0.5.8 vs lib/sewing_kit/webpack/helper.rb in sewing_kit-0.6.0
- old
+ new
@@ -10,21 +10,20 @@
class UnknownJavaScriptAssetError < StandardError
end
def sewing_kit_asset_paths(source, extension: 'js')
return '' unless source.present?
- return '/webpack/assets/dll/vendor.js' if Rails.env.development? && 'vendor' == source && extension == 'js'
- return '' if ['runtime', 'vendor'].include?(source) && !Rails.env.production?
+ return '/webpack/assets/dll/vendor.js' if serve_development_asests && 'vendor' == source && extension == 'js'
paths = SewingKit::Webpack::Manifest.asset_paths(source)
return '' unless paths[extension]
[paths[extension]].flatten.reject { |path| path =~ /.*\.map$/ }
end
def sewing_kit_link_tag(*paths)
- return '' unless Rails.env.production?
+ return '' unless serve_compiled_assets
options = paths.extract_options!
tags = paths.uniq.map { |path|
create_asset_tag(:link, path, options)
@@ -36,12 +35,11 @@
def sewing_kit_script_tag(*paths)
options = paths.extract_options!
tags = paths.uniq.map { |path|
if path == ''
- next '' unless Rails.env.production?
- raise UnknownJavaScriptAssetError.new('Empty JavaSscript path passed to sewing_kit')
+ next ''
end
create_asset_tag(:script, path, options)
}
@@ -77,9 +75,17 @@
def extract_hash(path)
# Consumes sewing-kit's [name]-[chunkhash].[ext] format
return unless path =~ /.*-[A-Za-z0-9]{64}\.(js|css)/
path.rpartition('-').last.split('.').first
+ end
+
+ def serve_compiled_assets
+ Rails.env.production? || ENV['SK_SIMULATE_PRODUCTION'] == '1'
+ end
+
+ def serve_development_asests
+ !serve_compiled_assets
end
end
end
end