shinate / gulp-version-number

Add version number to js/css/image in HTML
MIT License
24 stars 19 forks source link

Add support for ng-href and on<events> in link tag #8

Open lawmercado opened 5 years ago

lawmercado commented 5 years ago

I found out that:

<link ng-href="themes/{{theme||'default'}}/css/style.css" rel="stylesheet" onerror="this.href='themes/experter/css/style.css'">

is being parsed as:

<link ng-href="themes/{{theme||?v=44edd1b317271634126140a94694357b'default'}}/css/style.css" rel="stylesheet" onerror="this.href='themes/experter/css/style.css'">

which is not the expected output. The expected output should be:

<link ng-href="themes/{{theme||'default'}}/css/style.css?v=44edd1b317271634126140a94694357b" rel="stylesheet" onerror="this.href='themes/default/css/style.css?v=44edd1b317271634126140a94694357b''">

I'm using version 0.1.7, using the version config as shown below:

const versionConfig = {
    'value': '%MDS%',
    'append': {
        'key': 'v',
        'to': ['js', 'css', 'sass'],
    },
};
shinate commented 5 years ago

now, custom attribute supported. "append.to.{Object}.attr"

lawmercado commented 5 years ago

Nice. But this does not solves the problem related to ng-href , right?

shinate commented 5 years ago

attribute is ['href', 'ng-href', ...] which you want to append

lawmercado commented 5 years ago

Both of these attributes. As I understand, using

const versionConfig = {
    'value': '%MDS%',
    'append': {
        'key': 'v',
        'to': [
            {
                'type': 'js'
            },
            {
                'type': 'css',
                'attr': ['href', 'ng-href', 'onerror']
            }
        ],
    },
};

Is giving me this output

<link ng-href="themes/{{theme|| ?v=2b0b76da590ce4487593d2b93d10295c'default}}/css/style.css" rel="stylesheet" onerror="this.href=?v=2b0b76da590ce4487593d2b93d10295c'themes/default/css/style.css'">

Which is not right. I'm defining versionConfig wrong?

shinate commented 5 years ago

I think that's not a standard link 😆, it contains templates or logic. Why not use the replacement mode

lawmercado commented 5 years ago

I see. Even if is not a standard link, the regex used do match links should be able to deal with this (since is a valid syntax).

And did you notice that the generated onerror's attribute link is wrong too?