rails / sprockets

Rack-based asset packaging system
MIT License
947 stars 788 forks source link

assets:precompile & closure compressor/compiler adds debug text to javascript files #800

Closed patrickkulling closed 9 months ago

patrickkulling commented 9 months ago

Actual behavior

When I am compressing my javascript files, the closure compressor/compiler is adding some log output at the beginning of the final file, which makes it non legit javascript anymore.

This behaviour is slightly different locally & when hosting on heroku.

heroku:

Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8

locally:

Jan 04, 2024 4:37:37 PM com.google.javascript.jscomp.PhaseOptimizer$NamedPass process
WARNING: Skipping pass checkConformance
'use strict';

Any hints are appreciated?

System configuration

closure-compiler (1.1.14) sprockets (4.2.1) ruby 3.1.1p18

Example

require 'closure-compiler'

Closure::Compiler::DEFAULT_OPTIONS[:language_in] = 'ECMASCRIPT_2017'
Closure::Compiler::DEFAULT_OPTIONS[:language_out] = 'ECMASCRIPT6'

root = File.dirname(__FILE__)

sprockets = Sprockets::Environment.new(root)
sprockets.js_compressor = :closure

task :precompile do
    assets = [
      File.join(Application.root, 'assets', 'stylesheets', 'application.css'),
      File.join(Application.root, 'assets', 'javascripts', 'application.js'),
      Dir.glob(File.join(Application.root, 'assets', 'images', '*.*'))
    ]

    manifest = Sprockets::Manifest.new(Application.sprockets, File.join(Application.public_folder, Application.assets_prefix))

    manifest.compile(assets)
  end
patrickkulling commented 9 months ago

Closing this as this may be more an issue for the closure-compiler gem instead