gulp-useref:更新查找路径并在使用.restore 函数之前添加某个变量
gulp-useref: update look up path and the prepend a certain variable before using .restore function
我正在尝试将 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
我们最近遇到了类似的问题,gulp-replace
在这里做得很好。你会像这样使用它:
gulp.src('path/to/my/index.html')
.pipe(replace(/{{ STATIC_URL }}dash/g,'withsomethingelse')
.pipe(/* start the useref stuff now */)
我不确定 gulp 将如何处理路径...可能是您必须将静态 URL 替换为与 index.html 相关的内容,而不是gulp文件。
我正在尝试将 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
我们最近遇到了类似的问题,gulp-replace
在这里做得很好。你会像这样使用它:
gulp.src('path/to/my/index.html')
.pipe(replace(/{{ STATIC_URL }}dash/g,'withsomethingelse')
.pipe(/* start the useref stuff now */)
我不确定 gulp 将如何处理路径...可能是您必须将静态 URL 替换为与 index.html 相关的内容,而不是gulp文件。