importmap-rails | Use ESM with importmap to manage modern JavaScript

 by   rails Ruby Version: v1.1.6 License: MIT

kandi X-RAY | importmap-rails Summary

kandi X-RAY | importmap-rails Summary

importmap-rails is a Ruby library typically used in Utilities, Angular, React, Webpack, Nodejs applications. importmap-rails has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

Import maps let you import JavaScript modules using logical names that map to versioned/digested files – directly from the browser. So you can build modern JavaScript applications using JavaScript libraries made for ES modules (ESM) without the need for transpiling or bundling. This frees you from needing Webpack, Yarn, npm, or any other part of the JavaScript toolchain. All you need is the asset pipeline that's already included in Rails. With this approach you'll ship many small JavaScript files instead of one big JavaScript file. Thanks to HTTP/2 that no longer carries a material performance penalty during the initial transport, and in fact offers substantial benefits over the long run due to better caching dynamics. Whereas before any change to any JavaScript file included in your big bundle would invalidate the cache for the the whole bundle, now only the cache for that single file is invalidated. There's native support for import maps in Chrome/Edge 89+, and a shim available for any browser with basic ESM support. So your app will be able to work with all the evergreen browsers.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              importmap-rails has a medium active ecosystem.
              It has 861 star(s) with 100 fork(s). There are 37 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 23 open issues and 79 have been closed. On average issues are closed in 42 days. There are 7 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of importmap-rails is v1.1.6

            kandi-Quality Quality

              importmap-rails has 0 bugs and 0 code smells.

            kandi-Security Security

              importmap-rails has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              importmap-rails code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              importmap-rails is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              importmap-rails releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.
              It has 993 lines of code, 68 functions and 60 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of importmap-rails
            Get all kandi verified functions for this library.

            importmap-rails Key Features

            No Key Features are available at this moment for importmap-rails.

            importmap-rails Examples and Code Snippets

            No Code Snippets are available at this moment for importmap-rails.

            Community Discussions

            QUESTION

            Rails 7 ActionCable Unable to Connect
            Asked 2022-Mar-09 at 22:08

            I recently upgraded from Rails 6.1.4.6 to 7.0.2.2. With this upgrade I switched from webpacker to import maps with sprockets. My repo didn't include turbolinks or stimulus and I didn't feel like adding them now either. So I re-added UJS and most of my tests pass except the action cable feature tests. It seems I cannot get action cable to connect.

            Any help would be appreciated!

            Gemfile

            ...

            ANSWER

            Answered 2022-Mar-09 at 22:08

            Figured out the problem was because I had two applications.js files. One in app/assets/javascripts/ and another in app/javascript. Sprockets was serving my asset version of application.js due to my manifest pointing there. I adjusted the manifest and deleted the secondary application.js and all is working.

            Source https://stackoverflow.com/questions/71358357

            QUESTION

            Rails - errors partial not rendering
            Asked 2022-Feb-16 at 07:10

            I'm very new to Rails and full-stack development in general. I've just finished Michael Hartl's Ruby on Rails Tutorial 6th edition and am walking through it again to build my first project (i.e. an app that's different from the sample app built in the book, but draws on a lot of the same lessons). Catch is that new project is using Rails 7.

            It was going well until I ran into issues around Chapter 7; my app will not render a partial with error messages for bad submissions to the new user form. The code in the partial executes (as verified with debugger, and later with a puts statement to output on console), but the HTML doesn't output (i.e. it cannot be found when inspecting the page in Chrome). There is a CSS issue related to newer version of bootstrap, but I even tried downgrading to the bootstrap version from the book (3.4.1) with no luck. (the offending CSS segment is commented out below)

            I've banged my head on this for a few hours. Hoping it's just something dumb I'm missing. If it's a broader issue with Bootstrap vs Importmaps or something I'd also appreciate references on good places to learn these. I am extremely grateful for any ideas!

            Edit This definitely isn't an issue with passing local variables into the partial; see code snippet and comment added at the end of this post.

            app/views/users/new.html.erb:

            ...

            ANSWER

            Answered 2022-Feb-14 at 02:28

            Try this in app/views/users/new.html.erb

            <%= render 'shared/error_messages', user: @user %>

            If it's a shared partial, maybe make the instance variable generic rather than @user also. That way it can be reused and less confusing later.

            Source https://stackoverflow.com/questions/71106166

            QUESTION

            Rails 7 - link_to with method :delete still performs GET request
            Asked 2022-Feb-10 at 18:02

            I am trying to get this link to work, performing a DELETE request:

            ...

            ANSWER

            Answered 2021-Dec-25 at 22:28

            As suggested here, the following will suffice:

            Source https://stackoverflow.com/questions/70474422

            QUESTION

            Bootstrap 5 Javascript Functions not Working in Rails 7 app
            Asked 2022-Jan-29 at 22:51

            I'm trying to set up my first Rails 7 app and have installed Bootstrap 5 properly (you can see by the CSS) and gotten rid of all the error messages, but the javascript functions (i.e. dropdown menus, offcanvas, etc.) aren't working.

            I have tested it with this code:

            ...

            ANSWER

            Answered 2022-Jan-29 at 22:51

            I had the same problem.

            I got things working by adding the bundle script from Bootstrap in the between the body tags of the application.html.erb file:

            Source https://stackoverflow.com/questions/70907799

            QUESTION

            How to install Highlight.js to Rails 7 with importmap?
            Asked 2022-Jan-11 at 09:16

            I created a simple Rails 7 application with Post, Comment models using Tailwindcss.

            And I have a problem with importing the highlight.js library to render syntax code in Trix editor.

            This is config/importmap.rb:

            ...

            ANSWER

            Answered 2022-Jan-11 at 03:16

            It looks like you import highlight.js in your application.js then attempt to import it again from the pinned location which is not the pattern recommended in importmaps documentation.

            Try either importing the entirety of highlight.js or just import the specific languages you want.

            Try updating the imports on your application.js file and removing the language specific

            Source https://stackoverflow.com/questions/70656496

            QUESTION

            Rails 7 Semantic-UI jQuery "Uncaught ReferenceError" Using Importmaps
            Asked 2022-Jan-10 at 19:11
            Issue Summary

            I have a new rails 7 application which is using the importmap-rails gem to manage the javascript frontend libraries.

            I am attempting to use the Semantic-UI library, but the dependency for jQuery is not being recognized by the Semantic-UI javascript.

            I was unable to pin the Semantic-UI library via importmap, so I added this library to the importmap.rb manually. Here is a link the cdn for semantic.min.js I am using.

            The following error message appears in the console on Chrome Web Tools and the collapsible accordions are not functioning that I have on the page to validate the javascript.

            ...

            ANSWER

            Answered 2022-Jan-10 at 19:11

            I resolved this issue by manually updating the source for jquery pinned in importmap.rb from the source that the original bin/importmap pin jquery pointed at which was:

            https://ga.jspm.io/npm:jquery@3.6.0/dist/jquery.js

            to now be

            https://code.jquery.com/jquery-3.6.0.min.js

            Additionally, I added some jquery code to application.js to run when the document is loaded (per the documentation on Semantic-UI's website

            Source https://stackoverflow.com/questions/70655583

            QUESTION

            Import maps + Stimulus: error in JS "Unknown Content-Type text/html"
            Asked 2021-Oct-19 at 10:11

            I'm having a JS issue with my first Rails app, which I suspect is related to my using import maps instead of Webpack. I've searched and searched but haven't found any discussions of this.

            It's a Rails 6 app with some JS via Stimulus, which I installed by adding importmap-rails and then stimulus-rails. It works fine locally, but in production on Heroku the JS doesn't work and I see errors like this in the browser console: Uncaught (in promise) Error: Unknown Content-Type "text/html; charset=utf-8" doFetch https://plainreading.herokuapp.com/assets/es-module-shims-424762490b07cc7f9a37745e8b53356bca11997a8e313f47d780e29009df7e8e.js:580

            I'm wondering if it's because I removed Webpack from my app, using How to completely remove webpack and all its dependencies from Rails App. I removed it because I was getting Webpack-related build errors in Heroku, and it's my understanding that I don't need Webpack if I'm using import maps.

            A while ago I fixed a similar issue in a static site on Netlify by including this in its netlify.toml config:

            ...

            ANSWER

            Answered 2021-Oct-19 at 10:11

            In the end I solved the issue by doing the following:

            1. Install Rails 7 alpha.
            2. Create a test project with import maps: rails _7.0.0.alpha2_ new importmap-test. (You can use -j to set a different JS bundling option, such as -j esbuild, but the default is import maps.)
            3. Upgrade my main project to Rails 7 alpha.
            4. In my main project, make all JS-related code identical to the corresponding code in the test project. For me this meant overwriting app/javascript/controllers/index.js.

            Then my JS worked without errors.

            Source https://stackoverflow.com/questions/69572278

            QUESTION

            Add Hotwire to existing Rails 6.1 app using sprockets
            Asked 2021-Oct-01 at 12:34

            I'm trying to upgrade an existing Rails 6.1 with sprockets app to use stimulus. I installed

            ...

            ANSWER

            Answered 2021-Oct-01 at 12:34

            Error can be safely ignored I believe.

            Source https://stackoverflow.com/questions/69390309

            QUESTION

            Adding stimulus and importmaps to an existing Rails 6.1 app
            Asked 2021-Aug-24 at 12:40

            I've got a Rails 6.1 app which has been upgraded from Rails 4 -> 5 -> 6, so it's mature.

            It still uses asset pipeline and with the future of Rails 7.0 I'm going to keep it that way. I wanted to start using stimulus + importmaps, so I've followed along with the install.

            After installing importmaps and stimulus through hotwire I'm getting the following errors in Firefox 91 when loading my app;

            ...

            ANSWER

            Answered 2021-Aug-23 at 14:18

            Firefox does not support importmaps natively. You need to add a polyfill from https://github.com/guybedford/es-module-shims.

            Source https://stackoverflow.com/questions/68893273

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install importmap-rails

            Importmap for Rails is automatically included in Rails 7+ for new applications, but you can also install it manually in existing applications:. Note: In order to use JavaScript from Rails frameworks like Action Cable, Action Text, and Active Storage, you must be running Rails 7.0+. This was the first version that shipped with ESM compatible builds of these libraries.
            Add importmap-rails to your Gemfile with gem 'importmap-rails'
            Run ./bin/bundle install
            Run ./bin/rails importmap:install

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/rails/importmap-rails.git

          • CLI

            gh repo clone rails/importmap-rails

          • sshUrl

            git@github.com:rails/importmap-rails.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular Ruby Libraries

            rails

            by rails

            jekyll

            by jekyll

            discourse

            by discourse

            fastlane

            by fastlane

            huginn

            by huginn

            Try Top Libraries by rails

            rails

            by railsRuby

            webpacker

            by railsRuby

            thor

            by railsRuby

            jbuilder

            by railsRuby

            spring

            by railsRuby