Comments (12)
@pgilad could you help?
from grunt-jade-usemin.
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.
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.
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.
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.
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.
@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.
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.
@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.
There are 2 things to note here:
- Where you target your scripts using this plugin (should be your output compiled directory for scripts)
- 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.
@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.
👍
from grunt-jade-usemin.
Related Issues (20)
- Feature request: Incorporate file revision hash HOT 5
- filerev usage HOT 7
- Create examples.md which shows various usages examples
- Plugin fails when minblock has no tags
- Add option to specify destination directory for taks HOT 12
- It's not clear how to add config for tasks HOT 3
- filerev task doesn't work when using the same output file per two pages HOT 3
- filerev task doesn't work when using the same output file per two pages with targetPrefix HOT 1
- Included assets don't bundled? HOT 7
- How to override source js/css files with revved ones? HOT 6
- Source Maps HOT 2
- Warning: Task "concat:jadeUsemin-css" not found. HOT 15
- Should we fail when script src does not exist? HOT 2
- Pug files are not processed HOT 2
- possibly wrong warning on css&js build types HOT 3
- Task "concat:jadeUsemin" not found HOT 2
- Feature request - write target jade files after replacing build blocks
- Image path in css is not being replaced with relative or absolute path HOT 9
- location is not defined HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-jade-usemin.