GithubHelp home page GithubHelp logo

sbt-simple-url-update's People

Contributors

dwickern avatar micmro avatar neomaclin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sbt-simple-url-update's Issues

Cannot find dependency

I cannot find the dependency for this plugin. I've tried
addSbtPlugin("com.nurun.sbt" % "sbt-simple-url-update" % "1.0.0")
and
addSbtPlugin("com.nurun.sbt" % "sbt-simple-url-update" % "1.0.0-SNAPSHOT")
with
resolvers += Classpaths.sbtPluginSnapshots.

simpleUrlUpdate without sbt-rjs = updated /app/assets sources, not /target/web/

I've detected a bug, that takes place, if NO rjs presents in pipeline.

/app
  /assets
    /stylesheets
      /1.css

File 1.css contains something like this:

.some-icon {
    background-repeat: no-repeat;
    background-image: url('/assets/images/16.png');
}

build.sbt contains this:

pipelineStages ++= Seq(uglify, cssCompress, digest, simpleUrlUpdate, digest)

After calling sbt stage, original source file 1.css is modified by simpleUrlUpdate:

    background-image: url('/assets/images/0e62383352fa6de7092f51a29143260f-16.png');

Need to do hg revert after such stage...

File plugins.sbt contains this:

addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.2.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % "1.0.3")

addSbtPlugin("net.ground5hark.sbt" % "sbt-css-compress" % "0.1.3")

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.0-M3")

More robust URL replacement

If I have an asset, say images/logo.png, and then I have a URL on a different server that ends in the same path, http://example.com/images/logo.png, then the current implementation will fingerprint the example.com logo - not good.

A simple solution to this would be to only replace URLs in quotes (both single and double). In CSS, this has the limitation that unquoted URLs won't get replaced, but I think it's best practice to only use quoted URLs, so that's probably fine. In JS, I can't think of a place where you would have a URL that wasn't in a string by itself.

But then we have a problem, relative URLs are not correctly fingerprinted in CSS files, and it's very common to use relative URLs in CSS files - particularly when you're deploying to a CDN which might server assets from a different path, then you have to use relative URLs, eg ../images/foo.png.

So my suggestion is that you properly parse, at very least, the CSS, to find URLs, then process those URLs to work out which asset they are referring to locally. I've got some example regexps that I wrote some time ago here:

  val QuotedString = """(?:"[^"]*")|(?:'[^']*')"""

  val UrlRegex = ("""url\(\s*(""" + QuotedString + """|[^"'()\s\\]*)\s*\)""").r
  val ImportRegex = ("""@import\s+(""" + QuotedString + """)\s*;""").r

This will ensure that only URLs inside of url(...) or after an @import statement are matched. Another nice thing about this is it means you only run two regular expressions over each file, rather than running one regexp for every asset. It does make replacement a bit harder (you need to go through and manage a StringBuilder, using the start/end methods on the match group to transfer the parts of the file in between etc), but it means you can easily handle relative URLs, include URLs that traverse up like ../images/foo.png, and also absolute path URLs correctly.

I don't think there's an equivalent solution for JavaScript, but at least in JavaScript you generally don't need to deal with relative URLs in the same way that you need to in CSS, it should be sufficient there to just replace quoted URLs.

Re-write urls for minified files also

It'd be great to also look for -min.[(js)|(css)] and .min.[(js)|(css)] files also. If the min exists then rewrite the urls for that. This is exactly what Play's reverse router is doing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.