andrewb
jQuery, Font Awesome and Sockets
Hi,
I have a new Phoenix project (Latest versions of everything) and have a problem when I use:
import socket from "./socket"
I am using jQuery to highlight my menu and each menu item has an icon from Font Awesome. In my app.js I am defining jQuery like this:
window.$ = $;
and the script in my base layout HTML is:
var page = window.location.pathname.split('/')[1]
$('#' + page).toggleClass('active')
I am also importing the icons in app.js:
import { faUser } from "@fortawesome/pro-light-svg-icons/faUser";
library.add(faUser);
when I use the import statement for sockets I get an error uncaught reference error: $ is undefined and my icons disappear.
I have tried moving script to view render function but same problem exists … only thing that fixes it is commenting out the import for sockets.
Thanks in advance,
Andrew
Most Liked
peerreynders
I am trying to work out why importing that script makes a difference.
Just because it worked before doesn’t mean it’s a good idea.
Mixing in-page script and modules is a Bad Idea™.
If you plan to use webpack move your code into a module (or all of it into app.js). I described the process in principle here (for Brunch - but the idea is the same). For some more background into bundling see Modern JavaScript Explained For Dinosaurs.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








