17

我的应用程序的目录如下

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' ] },

如果目录如下

应用程序-> 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 的脚本内容,我该如何控制该流程?有时它会从脚本中去除 angular-sanitize [src]

4

3 回答 3

13

你应该使用wiredep的replace选项:

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

会产生:

<script src="/app/appName/bower_components/angular/angular.js"></script>
于 2015-07-31T12:50:59.597 回答
9

这是我的 gulp 设置(同样的原则适用于 Grunt,只需将相同的选项传递给它)。

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

您可以查看 lib/inject-dependencies.js 中的wiredep源代码(行:80~85)

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

它只是替换您提供的位(或者如果您不给它一个)。

希望有帮助。

于 2015-08-23T00:49:05.427 回答
5

您是否尝试过添加cwdoptions块中?

前任:

  // Automatically inject Bower components into the app
    wiredep: {
      options: {
        cwd: 'app/appName'
      }
      ....
    }
于 2014-08-10T03:08:45.983 回答