app.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. // We need to import the CSS so that webpack will load it.
  2. // The MiniCssExtractPlugin is used to separate it out into
  3. // its own CSS file.
  4. import "../css/app.scss"
  5. // webpack automatically bundles all modules in your
  6. // entry points. Those entry points can be configured
  7. // in "webpack.config.js".
  8. //
  9. // Import deps with the dep name or local files with a relative path, for example:
  10. //
  11. // import {Socket} from "phoenix"
  12. // import socket from "./socket"
  13. //
  14. import "phoenix_html"
  15. import {Socket} from "phoenix"
  16. import NProgress from "nprogress"
  17. import {LiveSocket} from "phoenix_live_view"
  18. let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
  19. let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
  20. // Show progress bar on live navigation and form submits
  21. window.addEventListener("phx:page-loading-start", info => NProgress.start())
  22. window.addEventListener("phx:page-loading-stop", info => NProgress.done())
  23. // connect if there are any LiveViews on the page
  24. liveSocket.connect()
  25. // expose liveSocket on window for web console debug logs and latency simulation:
  26. // >> liveSocket.enableDebug()
  27. // >> liveSocket.enableLatencySim(1000)
  28. window.liveSocket = liveSocket