0

我正在尝试将 gulp-useref 与 django 一起使用。我所有的注入脚本都工作正常,注入后进行手动路径更新,但现在我想连接我注入的脚本。这是我的html

  <!-- build:css({compile/serve,src}) styles/vendor.css -->
  <!-- bower:css -->
  <link rel="stylesheet" href="{{ STATIC_URL }}dash/bower_components/angular-material/angular-material.css" />
  <link rel="stylesheet" href="{{ STATIC_URL }}dash/bower_components/nvd3/src/nv.d3.css" />
  <!-- endbower -->
  <!-- endbuild -->

  <!-- build:css({compile/serve,src}) styles/app.css -->
  <!-- inject:css -->
  <link rel="stylesheet" href="{{ STATIC_URL }}dash/compile/serve/styles/main.css">
  <!-- endinject -->
  <!-- endbuild -->

  <!-- build:js(src) scripts/vendor.js -->
  <!-- bower:js -->
  <script src="{{ STATIC_URL }}dash/bower_components/angular/angular.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/angular-animate/angular-animate.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/angular-cookies/angular-cookies.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/angular-touch/angular-touch.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/angular-sanitize/angular-sanitize.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/angular-resource/angular-resource.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/angular-route/angular-route.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/angular-aria/angular-aria.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/angular-material/angular-material.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/angular-messages/angular-messages.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/pace/pace.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/d3/d3.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/nvd3/nv.d3.js"></script>
  <script src="{{ STATIC_URL }}dash/bower_components/angularjs-nvd3-directives/dist/angularjs-nvd3-directives.js"></script>
  <!-- endbower -->
  <!-- endbuild -->

  <!-- build:js({compile/serve,src}) scripts/app.js -->
  <!-- inject:js -->
  <script src="{{ STATIC_URL }}dash/src/js/dashboard/services/api/campaigns.js"></script>
  <script src="{{ STATIC_URL }}dash/src/js/dashboard/controllers/navigation/sidebar.js"></script>
  <script src="{{ STATIC_URL }}dash/src/js/dashboard/controllers/navigation/header.js"></script>
  <script src="{{ STATIC_URL }}dash/src/js/dashboard/controllers/forms/company-settings.js"></script>
  <script src="{{ STATIC_URL }}dash/src/js/dashboard/controllers/forms/campaign-create.js"></script>
  <script src="{{ STATIC_URL }}dash/src/js/dashboard/directives/file-reader.js"></script>
  <script src="{{ STATIC_URL }}dash/src/js/app.js"></script>
  <!-- endinject -->

  <!-- inject:partials -->
  <!-- angular templates will be automatically converted in js and inserted here -->
  <!-- endinject -->
  <!-- endbuild -->

我只想{{ STATIC_URL }}dash从路径中删除,因为这是我的 gulpfile.js 所在的根目录(不同于 index.html 目录),将脚本处理到相应的文件中,然后使用编译 css 和 js 更新我的 index.html ..但预先{{ STATIC_URL }}dash

4

1 回答 1

5

我们最近遇到了类似的问题,gulp-replace在这里做得很好。你会以某种方式使用它:

gulp.src('path/to/my/index.html')
  .pipe(replace(/{{ STATIC_URL }}dash/g,'withsomethingelse')
  .pipe(/* start the useref stuff now */)

我不确定 gulp 在路径方面的表现如何......可能是你必须用相对于 index.html 而不是 gulpfile 的东西替换静态 URL。

于 2015-04-16T21:21:11.413 回答