spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

sprockets - precompiling a standalone asset


One way to do this is to add an initializer that generates the compiled versions directly.

  1. Add your js file to a subfolder in /app/assets/javascripts. Don't include this in application.js so it isn't added to the compiled assets.
  2. Create an initializer in /config/initializers that uses uglify directly

    output_file = "#{Rails.root}/public/public_script.js"

    input_file = "#{Rails.root}/app/assets/javascripts/non_digest/public_script.js"

    uglified = Uglifier.compile(File.read(input_file))

    File.open(file, 'w') {|f| f.write(uglified) }

  3. Include the public js file (in this example: /public/public_script.js) in your application layout

This way you have direct access to make custom changes to how uglify handles your js and the location of the file never changes for your external services accessing them.

I did all this locally and tested that it worked using the beta version of Rails 4.2


Categories : Ruby On Rails

Related to : sprockets - precompiling a standalone asset
Asset pipeline with rails/sprockets & bower
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.ico) config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components', 'bootstrap-sass-official', 'assets', 'fonts') config.assets.precompile << %r(.*.(?:eot|svg|ttf|woff)$) config.assets.precompile = ['*.js', '*.css', '*.css.erb'] This last line overwrites the previous two lines which add the image assets to prec

Categories : Ruby On Rails
What is the difference between sprockets-rails and sprockets gem?
The sprockets-rails includes rails based functionality and rake tasks. In all current versions of Rails (beginning with 3.1), your Sprockets environment is automatically mounted at /assets. Sprockets can be used in conjunction with a Rack app. See: https://github.com/rack/rack for more information regarding Rack apps.

Categories : Ruby On Rails
Requiring a sprockets-preprocessed file with Browserify and browserify-rails
I’ve spent endless hours on integrating browserify-rails in my project and making JS Routes work within this setup… The solution I came to and described below is the result of me not being able to have Sprockets pre-process my routes file before Browserify would come in. I have spent quite some time in both the source code of browserify-rails and sprockets but couldn't find a way to turn thin

Categories : Javascript
Asset pipeline undefined variable
remove the *= require_tree . otherwise, you load everything twice and also there is no chance to load it in the correct order. rails just load it in a "random" way and then u most of the time run into errors.

Categories : Ruby On Rails
Can we use asset html files in Alert dialog?
try this way, try { InputStream is = getAssets().open("yourhtmlfile.txt"); // We guarantee that the available method returns the total // size of the asset... of course, this does mean that a single // asset can't be more than 2 gigs. int size = is.available(); // Read the entire asset into a local byte buffer.

Categories : Android
Recently Add
Groups and Users has many oder has many through?
Rails format specifier differences
Capistrano can not create symlinks: file exist
Admin can't delete users. Ruby on Rails 3 - Michael Hartl
Don't show user name who create post
Using Wicked with Devise (2 step signup process)
RubyOnRails Rake test failures
Rails session start event handler
Why ActiveModel::ForbiddenAttributesError error?
How can i track the issue in production RAILS
Cannot install spree gem - ERROR: invalid gem: package is corrupt
Why are the nested resources for Devise authentication not working?
Rails Devise - how to open access to the site root
Rails: respond_with the same template for two methods
rails with postgresl database "role postgres does not exist"
Instance variable in Rails helper not set
Monkey patch rails 3.2 rake task
Rails_admin: Should I have admin_user or user with admin role to manage users and admin panel
undefined method `attachments' for nil:NilClass
Memory usage increase with Ruby 2.1 versus Ruby 2.0 or 1.9
Can a Rails app be deployed without using Heroku Toolbelt? If so, how?
Enable random access to collection with MongoDB
libmysqlclient-dev installation fails
undefined method `name' for nil:NilClass. Can't find @followed.name but @followed is set
Allowing an arbitrary domain and subdomain in session_store.rb
Pushmeup Gem - Can't send push notifications in Active Admin model
Rails console does not start
GitHub Import: Could not locate Gemfile
AWS::S3::PermanentRedirect in SongsController#index "The bucket you are attempting to access must be addressed using the specified endpoint"
automatically create ActiveRecord parent for association
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.