jasonm / ngmin-rails

DEPRECATED [Was: Use ngmin in the Rails asset pipeline.]
MIT License
42 stars 13 forks source link

add Ngmin::Processor into bundle processor, so make module defined in seperate file works #8

Closed raykin closed 10 years ago

raykin commented 11 years ago

After searching the source, sprockets considered js and css as bundled assets and always run bundle prorcessor when run rake assets:precompile.

# sprockets/mainfest.rb
    def compile(*args)
      unless environment
        raise Error, "manifest requires environment for compilation"
      end

      paths = environment.each_logical_path(*args).to_a +
        args.flatten.select { |fn| Pathname.new(fn).absolute? if fn.is_a?(String)}

      paths.each do |path|
        if asset = find_asset(path)

the last line will create a bundled asset for javascript asset. So only the user override the compile and write something like

   if asset = find_asset(path, bundle: false)

Then the bundle processor will be ignore.

Actually that's how development env did. In development, we query http://localhost:3000/assets/ctrl/doc.js?body=1 to get each js file if the rails config config.assets.debug = true. then sprockets will render this js asset as ProcessedAsset, no any processors run.

# sprockets/server
      def call(env)
      ... 
       # Look up the asset.
      asset = find_asset(path, :bundle => !body_only?(env))
      ...
      end

      # Test if `?body=1` or `body=true` query param is set
      def body_only?(env)
        env["QUERY_STRING"].to_s =~ /body=(1|t)/
      end

Since we only care about the rake assets:precompile, I think it's safe to remove the postprocessor

jasonm commented 10 years ago

Hi @raykin - sorry for the delayed response. I haven't used this (or Angular) in a long time, so I'm deprecating the project in favor of ngannotate-rails, which makes use of ng-annotate which possibly supercedes ngmin.