magnars / optimus

A Ring middleware for frontend performance optimization.
364 stars 23 forks source link

Source maps #58

Closed kendagriff closed 7 years ago

kendagriff commented 7 years ago

Any suggestions for delivering a source map? At the end of the bundle.js file there is

//# sourceMappingURL=bundle.js.map

But, of course, that file can't be found at /token/bundle.js.map. Any ideas?

magnars commented 7 years ago

What is creating these source maps? man. 15. mai 2017 kl. 22.04 skrev Kendall Buchanan <notifications@github.com

:

Any suggestions for delivering a source map? At the end of the bundle.js file there is

//# sourceMappingURL=bundle.js.map

But, of course, that file can't be found at /token/bundle.js.map. Any ideas?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/magnars/optimus/issues/58, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQOORRbHzlfK8MEosIwx5BtHQRN5lOlks5r6K-1gaJpZM4NbnyB .

kendagriff commented 7 years ago

The map is output from a webpack bundle (as is bundle.js). So, yeah, not the result of any combined files in optimus...

magnars commented 7 years ago

Okay, so you just want to serve it via optimus? You can use regex in load-assets. Something like this?

(defn get-assets []
  (concat
   ;; ...
   (assets/load-assets "public" [#"/token/.+\.js\.map"])))
kendagriff commented 7 years ago

I should have clarified that bundle.js is being served by Optimus with a cache busting URL (e.g. /cache-busting-hash/bundle.js).

How can the source map share the same directory, so it can be retrieved relative to bundle.js?

On Tue, May 16, 2017 at 2:50 AM Magnar Sveen notifications@github.com wrote:

Okay, so you just want to serve it via optimus? You can use regex in load-assets. Something like this?

(defn get-assets [] (concat ;; ... (assets/load-assets "public" [#"/token/.+.js.map"])))

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/magnars/optimus/issues/58#issuecomment-301717600, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGxV_vtbBAntirfgepAX2dWfBG52UkYks5r6WNigaJpZM4NbnyB .

magnars commented 7 years ago

In this case, you will have to do a bit of coding yourself. :)

Remember, the assets are just data. They are a seq of maps: [{:path :contents}]. Write your own function that looks for sourceMappingURL in :contents and fixes it. Then plug it into the optimization middleware chain (see https://github.com/magnars/optimus#specifying-the-optimizations)

There's more info on how assets work here: https://github.com/magnars/optimus#what-are-these-assets-anyway-they-seem-magical-to-me

kendagriff commented 7 years ago

Makes sense! Thank you, thank you.