Giter VIP home page Giter VIP logo

source_maps_fixer's Introduction

SourceMapsFixer

SourceMapsFixer is a set of Rake tasks for fixing sourceMappingURLs.
It is helpful for Rails apps where the main front-end code lives in the separate directory like frontend. But the app also uses Sprockets to process outputted bundles and additional assets inside app/assets directory. bin/rails assets:precompile command compiles assets to public/assets directory. Fingerprints are added to asset filenames during compilation by default. It is useful in conjunction with far-future headers.

Problem

When webpack produces bundles to app/assets/bundles, each contains sourceMappingURL at the bottom (if configured). This URL links to the corresponding source map.
But when Sprockets compile assets to public/assets, fingerprints are added to all asset filenames.
sourceMappingURLs are intact, which makes them point to invalid files without fingerprints.

Solution

SourceMapsFixer fixes sourceMappingURLs inside bundles.

๐ŸŽฎ Usage

Instead of running

$ bin/rails assets:precompile

run

$ bin/rails assets:prepare

๐Ÿ“ฅ Installation

Add source_maps_fixer to your application's Gemfile:

gem 'source_maps_fixer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install source_maps_fixer

๐Ÿ“ˆ Changelog

Major releases ๐ŸŽ™

0.2 (2022-02-11)

๐Ÿ’ฅ breaking changes
  • source_maps_fixer works with Rails 7 and Ruby 3.1.
  • it drops support for Ruby 2.6
  • it supports sprockets-rails ~> 3.3.0. Version 3.4.0 works differently. bin/rails assets:precompile correctly replaces sourceMappingURLs for JS files but adds unnecessary comments

๐Ÿ“œ License

The gem is available as open source under the terms of the MIT License.

๐Ÿ‘จโ€๐Ÿญ Author

Zbigniew Humeniuk from Art of Code

๐Ÿ‘€ See also

If you want to make your life easier in other areas of web app development, I strongly recommend you to take a look at my other project called the Loco framework ๐Ÿ™‚. It is pretty powerful and makes a front-end <-> back-end communication a breeze (among other things).

source_maps_fixer's People

Contributors

dependabot[bot] avatar himn1 avatar zbigh avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.