Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace src after injection #160

Open
chaouiy opened this issue Nov 7, 2016 · 2 comments
Open

replace src after injection #160

chaouiy opened this issue Nov 7, 2016 · 2 comments

Comments

@chaouiy
Copy link

chaouiy commented Nov 7, 2016

How to replace :

<script src="../../../bower_components/angular/angular.js"></script>

by :

<script src="{% static 'angular/angular.js'}"></script>

@marcoooo
Copy link

marcoooo commented Mar 22, 2017

+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
Copy link

You can use add the ignorePath parameter to ignore any relative path generated from your 'static' basepath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants