generator-gulp-angular icon indicating copy to clipboard operation
generator-gulp-angular copied to clipboard

gulp-wiredep to inject a new path for files

Open debuggerpk opened this issue 12 years ago • 5 comments

for django, i am trying to insert a relative path ..

the wiredep section of my older grunt file looked like this

wiredep: {
      dashboard: {
        src: '<%= backOffice.dashboard %>/base.html',
        exclude: ['/selectize/', '/sifter/', '/microplugin/'],
        ignorePath: '../../static/',
        fileTypes: {
          html: {
            replace: {
              js: '<script src="{{ STATIC_URL }}{{filePath}}"></script>',
              css: '<link rel="stylesheet" href="{{ STATIC_URL }}{{filePath}}" />'
            }
          }
        }
      }
    }

i am trying to do the same with my wiredep.js for gulp task and this is what it looks like

'use strict';

var gulp = require('gulp');

// inject bower components
gulp.task('wiredep', function() {
  var wiredep = require('wiredep').stream;

  gulp.src('src/{app,components}/*.scss')
    .pipe(wiredep({
      directory: 'src/bower_components'
    }))
    .pipe(gulp.dest('src'));

  gulp.src('../../templates/backoffice/__base.html')
    .pipe(wiredep({
      fileTypes: {
        html: {
          replace: {
            js: '<script src="{{ STATIC_URL }}{{filePath}}"></script>',
            css: '<link rel="stylesheet" href="{{ STATIC_URL }}{{filePath}}" />'
          }
        }
      }
    }));

but this isn't working, can anybody help?

debuggerpk avatar Oct 13 '14 17:10 debuggerpk

Do you install Django with 'bower install' ?

zckrs avatar Oct 13 '14 17:10 zckrs

django is a python package . there shouldn't be any need for it, i had been doing the same thing with grunt without using bower install package for django

debuggerpk avatar Oct 13 '14 17:10 debuggerpk

okay, must include the gulp.dest, the final looks like this

gulp.src('../../templates/backoffice/__base.html')
    .pipe(wiredep({
      ignorePath: '../../static/',
      fileTypes: {
        html: {
          replace: {
            js: '<script src="{{ STATIC_URL }}{{filePath}}"></script>',
            css: '<link rel="stylesheet" href="{{ STATIC_URL }}{{filePath}}" />'
          }
        }
      }
    }))
    .pipe(gulp.dest('../../templates/backoffice'));

debuggerpk avatar Oct 13 '14 17:10 debuggerpk

Right. Without gulp.dest you don't have new file.

zckrs avatar Oct 13 '14 17:10 zckrs

Hi, I seem to have a similar problem with wiredep prepending relative paths to bower_components in the processed html file.

Below is the code I have in my gulpfile.js and gulp.config.js

(gulpfile.js) gulp.task('wiredep', function () { log('Wire up the bower css js and our app js into the html'); var options = config.getWiredepDefaultOptions(); var wiredep = require('wiredep').stream;

return gulp
    .src(config.index)
    .pipe($.debug(true))
    .pipe(wiredep(options))
    .pipe($.inject(gulp.src(config.js)))
    .pipe(gulp.dest(config.client));

}

(gulp.config.js) var config = { /** * File paths / // all js to vet alljs: [ './src/__/.js', './*.js' ], build: './build/', client: client, server: server, temp: temp,

    css: temp + 'styles.css',
    fonts: './bower_components/font-awesome/fonts/**/*.*',
    htmltemplates: clientApp + '**/*.html',
    images: client + 'images/**/*.*',

    index: client + 'index.html',

    js: [
        clientApp + '**/*.module.js',
        clientApp + '**/*.js',
        '!' + clientApp + '**/*.spec.js',
    ],

    less: client + 'styles/styles.less',

    /*
     * template cache
     */
    templateCache: {
        file: 'template.js',
        options: {
            module: 'app.core',
            standAlone: false,
            root: 'app/'
        }
    },

    /*
     * browser sync
     */
    browserReloadDeplay: 1000,

    /*
     * Bower and NPM locations
     */
    bower: {
        json: require('./bower.json'),
        directory: './bower_components/',
        ignorePath: '../..'
    },

    /**
     * Node settings
     */
    defaultPort: 7203,
    nodeServer: './src/server/app.js'
};

config.getWiredepDefaultOptions = function () {
    var options = {
        bowerJson: config.bower.json,
        directory: config.bower.directory,
        ignorePath: config.bower.ignorePath
    };
};

Index.html (before running gulp task)

<!-- build:css styles/lib.css -->
<!-- bower:css -->
<link rel="stylesheet" href="/bower_components/font-awesome/css/font-awesome.css" />
<link rel="stylesheet" href="/bower_components/toastr/toastr.css" />
<!-- endbower -->
<!-- endbuild -->

index.html (after running gulp task)

<!-- build:css styles/lib.css -->
<!-- bower:css -->
<link rel="stylesheet" href="../../bower_components/font-awesome/css/font-awesome.css" />
<link rel="stylesheet" href="../../bower_components/toastr/toastr.css" />
<!-- endbower -->
<!-- endbuild -->

Any pointer would be highly appreciated!

jlu1202 avatar Jul 24 '15 01:07 jlu1202