Add attribute to wiredep or gulp-inject css link?

442 Views Asked by At

How can I add a custom html attribute to one css file using either wiredep or gulp-inject? Every single other file is injected automatically, using Gulp, except for this one file (because I need to add an attribute to it):

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<title page-title></title>

<!-- build:css styles/lib.css -->
<!-- bower:css -->
<!-- endbower -->
<!-- endbuild -->

<!-- build:css styles/app.css -->
<!-- inject:css -->
<!-- endinject -->
<link id="loadBefore" href="/theme/css/style.css" rel="stylesheet">
<!-- endbuild -->
1

There are 1 best solutions below

0
Chris Aelbrecht On

Use the transform option in the inject command in your gulp file

var addIdToCss = function (filepath, file, i, length) {
    return '<link rel="stylesheet" href="' + filepath + '" id="YourId">';
}

inject(yourFile, {transform: addIdToCss, ...})