Git Product home page Git Product logo

Comments (12)

skotchio avatar skotchio commented on August 28, 2024

@pgilad could you help?

from grunt-jade-usemin.

pgilad avatar pgilad commented on August 28, 2024

I don't think there is a middle way here (without adding an option). If you want to go with absolute paths, that's fine, but you will need to specify the full path to output to. for example, in your case, that might be:
//-<!-- build:js /home/skotchio/projects/whatever/public/js/scripts.min.js -->

But if you go with relative paths, they will be relative to your project root. It's impossible to guess which option you want without adding an option for that (which I'm very reluctant to do, this plugin is already loaded with options). But if you must go with absolute path, just specify the entire path (from root of your system / ) to the compiled file.

from grunt-jade-usemin.

skotchio avatar skotchio commented on August 28, 2024

So if I write //-<!-- build:js /home/skotchio/projects/whatever/public/js/scripts.min.js --> then which src javascript attribute I'll get in processed jade?

from grunt-jade-usemin.

pgilad avatar pgilad commented on August 28, 2024

Why are you required to use absolute paths? Is that because of the way your routing is setup?
In your case (try it) I believe the processed jade will have the absolute path as target.

from grunt-jade-usemin.

skotchio avatar skotchio commented on August 28, 2024

My static processed by nginx by the following route:

location ~* \.(?:ico|css|js|gif|jpe?g|png) {
   root /var/www/myproject/static;
}

So I need my all javascript included in html looks like the following:

<html>
     <head>
            <script src="/js/scripts.min.js/"></script>
    </head>

from grunt-jade-usemin.

pgilad avatar pgilad commented on August 28, 2024

Ack I'm no nginx expert, but you can try url rewrite? so if someone hits with a public path you re-write it to your relative path (perhaps drop the non-needed part with regex).
Other than that, you can perhaps look for grunt plugins that will do src rewrite (something maybe like https://github.com/yoniholmes/grunt-text-replace but more sophisticated). Then you'll need to configure them to go over your target jade files and drop the absolute path that is specific to your system (and keep only the public/... parts)

from grunt-jade-usemin.

skotchio avatar skotchio commented on August 28, 2024

@pgilad Many sites require to use domain name in their scripts like:

 <html>
   <head>
        <script src="http://www.mysite.com/js/scripts.min.js/"></script>
  </head>

What in this case?

from grunt-jade-usemin.

pgilad avatar pgilad commented on August 28, 2024

I think that's usually bad design, since you always load the scripts from your domain root. The ones you don't are from cdn (or external), but either way - you don't compile them.
So the solution is to drop the leading / and go for relative routing.

Another solution is to use something like https://www.npmjs.org/package/grunt-string-replace to search and replace the scripts to their absolute counterparts... That's some work, but it's possible

from grunt-jade-usemin.

skotchio avatar skotchio commented on August 28, 2024

@pgilad your solusion about droping the leading / and go for relative routing is good but if I have the page with address http://www.mysite.com/user/profile/ and use relative path as you suggested:

<html>
<head>
    <script src="js/scripts.min.js/"></script>
</head> 
</html>

My scripts.min.js will be saved into user/profile/js folder which looks ugly.

from grunt-jade-usemin.

pgilad avatar pgilad commented on August 28, 2024

There are 2 things to note here:

  1. Where you target your scripts using this plugin (should be your output compiled directory for scripts)
  2. How you serve those scripts relies on how you configure your routing.

I suggest tweaking server routing to point at the location of the scripts, even if you use custom routing.
so mount the route: user/profile/js/:script to point to public/scripts/ and you should be fine.

Doing thing like re-writing urls in the build step, and using absolute urls is hard. It's possible but it's a lot of work.
Anyway my thoughts is that 1 plugin shouldn't be dealing with everything. As it is I think grunt-jade-usemin is too complex. I find that in the difficulty of some of the bug fixes.

If you feel that rewriting target urls is important, feel free to add a PR (with tests off course). But notice - it will have problems with things that rename file, such as the fileRev task.

from grunt-jade-usemin.

skotchio avatar skotchio commented on August 28, 2024

@pgilad Thanks for the answer I think I'll resolve my problem by using re-writing urls. Thanks for the help and for the good grunt plugin

from grunt-jade-usemin.

pgilad avatar pgilad commented on August 28, 2024

👍

from grunt-jade-usemin.

Related Issues (20)

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.