himn1
May 20, 2020, 10:24am
1
Hey!
Env: Rails 6, Sprockets 4
I spent quite a decent amount of time trying different config options without success. Sprockets keep dynamically adding
//# sourceMappingURL=application.js-a5970c2deb76a38d2c69d9af9da83dc5d4aeaf1d68444918b225e824475d8737.map
to the end of application.js in dev env.
I have inlined source maps at the end of this file already. I generate application.js using Webpack directly with its support for source maps.
So I would like to skip this redundant addition by Sprockets. Is this even possible? How to disable source maps support for Sprockets?
petrik
(Petrik de Heus)
June 4, 2020, 8:23pm
2
I haven’t tested this but you can delete Preprocessors:
# /* CSS
# *= require "baz"
# */
#
# This makes it possible to disable or modify the processor to do whatever
# you'd like. You could add your own custom directives or invent your own
# directive syntax.
#
# `Environment#processors` includes `DirectiveProcessor` by default.
#
# To remove the processor entirely:
#
# env.unregister_processor('text/css', Sprockets::DirectiveProcessor)
# env.unregister_processor('application/javascript', Sprockets::DirectiveProcessor)
#
# Then inject your own preprocessor:
#
# env.register_processor('text/css', MyProcessor)
#
class DirectiveProcessor
# Directives are denoted by a `=` followed by the name, then
You should probably be able to delete the Preprocessors::DefaultSourceMap
.
# frozen_string_literal: true
module Sprockets
module Preprocessors
# Private: Adds a default map to assets when one is not present
#
# If the input file already has a source map, it effectively returns the original
# result. Otherwise it maps 1 for 1 lines original to generated. This is needed
# Because other generators run after might depend on having a valid source map
# available.
class DefaultSourceMap
def call(input)
result = { data: input[:data] }
map = input[:metadata][:map]
filename = input[:filename]
load_path = input[:load_path]
lines = input[:data].lines.length
basename = File.basename(filename)
mime_exts = input[:environment].config[:mime_exts]
pipeline_exts = input[:environment].config[:pipeline_exts]
if map.nil? || map.empty?
This file has been truncated. show original
Maybe something like:
env.unregister_processor('application/javascript', Preprocessors::DefaultSourceMap)