assets-loader
assets-loader copied to clipboard
Asset loader doesn't transform file to web path
Hi,
I'm using play 2.2.2 and assets-loader 0.11.8. After configuring it I tried to use it to concatenate css files. When I launched the app, the file was correctly generated and placed into target/.assets-loader-generated folder
(in dev mode). However, the web path didn't lead to a file. Here is the last part of the log:
[debug] a.l.t.concatenator - name: /main-38678960.css
[trace] a.l.Sequence - transformer: com.ee.assets.transformers.Writer@4d68b29
[trace] a.l.new-loader - final path for generated asset: /Users/artem/vet/coiffure/target/.assets-loader-generated/main-38678960.css
[trace] a.l.Sequence - transformer: com.ee.assets.transformers.FileToWebPath@214a333a
[warn] a.l.file-to-web - /main-38678960.css doesn't contain public - so nothing to replace
After digging into source code I found that the last warning is coming from FileToWebPath.scala
file within this code:
if (!p.contains(info.filePath)) {
logger.warn(s"$p doesn't contain ${info.filePath} - so nothing to replace")
}
Just in case, here is my loader object
package util
import play.api.Play
import com.google.javascript.jscomp.CompilerOptions
object ScalaHelper{
val defaultOptions = new CompilerOptions()
defaultOptions.setLanguageIn(CompilerOptions.LanguageMode.ECMASCRIPT5)
val compilerOptions: Option[CompilerOptions] = Some(defaultOptions)
val loader = new com.ee.assets.Loader(None, Play.current.mode, Play.current.configuration, compilerOptions)
}
Thank you for the great tool and your help, Artem
A bit more insight.
The fact that app doesn't find css file at path localhost:9000/main-38678960.css
is no surprise to me. As, according to the routes file, assets-loader deals with routes /assets/*file
(I followed the readme when was setting it up).
The question is why assets-loader creates a path without /assets/
part.
Another thing is that when I try to manually request localhost:9000/assets/main-38678960.css
I get the following log (an empty response of course):
[trace] a.l.controller - path: public/main-38678960.css
[trace] a.l.controller - path to search: /Users/artem/vet/coiffure/target/.assets-loader-generated/public/main-38678960.css
the difference with the previous one is that now public
path is added.
Hi - it looks like its not resolving the path correctly, would need to have a look. Can you share a project that displays this behaviour. Feel free to fork and add it to the example (example/example-play-app
) and send a PR.
Thanks for reply, will try to do that today or tomorrow.
Btw, 2 things I've noticed as well. If I, instead of loading all css files within one call of loader, load them with at least two calls, routing works fine and css file are accessible.
But then appears another problem. I use libraries that use external files within css code like font-awesome and select2 (first contains links to font files, second - url to images). These libraries can't properly load external files after minification and concatenation. Maybe due to the fact that external files are not being copied to target folder with css file.
Thanks for the info.. re css concatenation - this is something that needs looking at. Either we only concat files in the same folder together (so that paths to other files are maintained), or we look up paths listed in the css and update the paths after processing or move the resources.
I will look at how sprocket etc work with this.
see #24 - for css issue