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

Gulp inject not inserting correctly in mustache template #136

Closed
nebulousGirl opened this issue Sep 17, 2015 · 2 comments
Closed

Gulp inject not inserting correctly in mustache template #136

nebulousGirl opened this issue Sep 17, 2015 · 2 comments

Comments

@nebulousGirl
Copy link

When I run gulp inject-css, the first everything is ok. But, when I run the command again the results is weird, the inject tag gets emptied out and code is randomly duplicated at the end of the file.

head.mustache:

<!DOCTYPE html>
<html class="no-js" lang="{{locale}}">
    <head>
        <meta charset="utf-8">
        <title>{{sitename}} | {{meta.title}}</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">

            <!-- bower:css -->
            <!-- endinject -->

        {{#stylesheets_external}}
        <link rel="stylesheet" type="text/css" href="{{{src}}}" media="{{media}}" />
        {{/stylesheets_external}}
        {{#stylesheets}}
        <link rel="stylesheet" type="text/css" href="{{{assets_url}}}{{{src}}}" media="{{media}}" />
        {{/stylesheets}}
        {{#scripts_head}}
        <script type="text/javascript" src="{{{assets_url}}}{{{.}}}"></script>
        {{/scripts_head}}
    </head>
    <body class="PAGE">
        <!--[if lte IE 8]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]--> 

gulpfile.js:

var gulp = require("gulp"),
    inject = require('gulp-inject'),
    bower_files = require('bower-files')();

var css_inject = function (filepath, file, i, length) {
    return '<link rel="stylesheet" href="' + filepath.replace('/bower_components', '{{{ assets_url }}}/vendor') + '" />';
};
var js_inject = function (filepath, file, i, length) {
    return '<script type="text/javascript" src="' + filepath.replace('/bower_components', '{{{ assets_url }}}/vendor') + '"></script>';
};
gulp.task('inject-css', function() {
        return gulp.src('./views/**/*.mustache').pipe(inject(gulp.src(bower_files.ext('css').files, {read: false, base: './bower_components' }), {name: 'bower', transform: css_inject}))
                .pipe(gulp.dest('./views'));
});
gulp.task('inject-js', function() {
        return gulp.src('./views/**/*.mustache').pipe(inject(gulp.src(bower_files.ext('js').files, {read: false, base: './bower_components' }), {name: 'bower', transform: js_inject}))
                .pipe(gulp.dest('./views'));
});
@nebulousGirl
Copy link
Author

Rolled back to 1.5.0 after others having issues with injecting and it works correctly. So, it is a bug from newer versions.

@joakimbeng
Copy link
Member

Duplicate of #135 which is solved in 3.0.0

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