replace src after injection
chaouiy opened this issue · 2 comments
chaouiy commented
How to replace :
<script src="../../../bower_components/angular/angular.js"></script>
by :
<script src="{% static 'angular/angular.js'}"></script>
marcoooo commented
+1
Found a kind of workaround for Django static (I guess that it's your problem)
-
I have two files (includes by Django in my templates)
- myapp/src/static/javascripts.html
- myapp/src/static/stylesheets.html
-
aside my bower.json, my bowerrc tells bower to put bower_components in src/static
-
within the wiredep config:
wiredep: {
task: {
// Point to the files that should be updated when
// you run `grunt wiredep`
src: [
'src/static/javascripts.html', // .html support...
'src/static/stylesheets.html', // .html support...
],
options: {
// See wiredep's configuration documentation for the options
// you may pass:
// https://github.com/taptapship/wiredep#configuration
fileTypes: {
html: {
block: /(([ \t]*)<!--\s*bower:*(\S*)\s*-->)(\n|\r|.)*?(<!--\s*endbower\s*-->)/gi,
detect: {
js: /<script.*src=['"]([^']+)/gi,
css: /<link.*href=['"]([^']+)/gi
},
replace: {
js: '<script src="{% static \'{{filePath}}\' %}"></script>',
css: '<link rel="stylesheet" href="{% static \'{{filePath.path}}\' %}" />'
}
}
}
}
}
}
``
from inside javascripts.html and stylesheets.html, bower components are at the same level, so static url is well parsed.
Hope It helps you.
marcoooo commented
You can use add the ignorePath parameter to ignore any relative path generated from your 'static' basepath