Как управлять тем, как wiredep генерирует путь к файлу bower и как контролировать, какие файлы добавляются/удаляются

В моем приложении есть каталог следующим образом

app → appName → index.html(js, css)

и по какой-то причине эта папка-оболочка appName испортила wiredire

{ dest: '.tmp/concat/scripts/vendor.js',
      src: 
       [ '../bower_components/es5-shim/es5-shim.js',
         '../bower_components/angular/angular.js',
         '../bower_components/json3/lib/json3.js',
         '../bower_components/angular-resource/angular-resource.js',
         '../bower_components/angular-cookies/angular-cookies.js',
         '../bower_components/angular-sanitize/angular-sanitize.js',
         '../bower_components/angular-animate/angular-animate.js',
         '../bower_components/angular-touch/angular-touch.js',
         '../bower_components/angular-route/angular-route.js' ] },

это то, что было бы создано, если каталог выглядит следующим образом

app → index.html(js, css)

{ dest: '.tmp/concat/scripts/vendor.js',
      src: 
       [ 'bower_components/es5-shim/es5-shim.js',
         'bower_components/angular/angular.js',
         'bower_components/json3/lib/json3.js',
         'bower_components/angular-resource/angular-resource.js',
         'bower_components/angular-cookies/angular-cookies.js',
         'bower_components/angular-sanitize/angular-sanitize.js',
         'bower_components/angular-animate/angular-animate.js',
         'bower_components/angular-touch/angular-touch.js',
         'bower_components/angular-route/angular-route.js' ] },

и wiredep меняет содержимое index.html script и как я могу управлять этим потоком? иногда его удаление angular -sanitize из его script [src]

Ответы

Ответ 1

Вы должны использовать опцию replace для проводной связи:

wiredep(
    {
        fileTypes: {
            html: {
                replace: {
                    js: '<script src="/app/appName/{{filePath}}"></script>'
                }
            }
        }
    })

Будет генерировать:

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

Ответ 2

Это моя установка gulp (тот же принцип применим к Grunt, просто передайте ему одни и те же параметры).

gulp.task('wiredep' , function()
{
    return gulp.src('./app/index.html')
           .pipe(wiredep({
               'ignorePath': '../'
           }))
          .pipe(gulp.dest('./app'));
});

Вы можете посмотреть исходный код wiredep в lib/inject-dependencies.js(строка: 80 ~ 85)

map(function (filePath) {
    return $.path.join(
      $.path.relative($.path.dirname(file), $.path.dirname(filePath)),
      $.path.basename(filePath)
    ).replace(/\\/g, '/').replace(ignorePath, '');
  }).

Он просто заменит бит, который вы поставляете (или нет, если вы его не дадите).

Надеюсь, что это поможет.

Ответ 3

Вы пытались добавить cwd в блок options?

Пример:

  // Automatically inject Bower components into the app
    wiredep: {
      options: {
        cwd: 'app/appName'
      }
      ....
    }