简体   繁体   中英

How to append to { asset ('/') }, prefix URL build gulp-useref task on my an includable page

I used gulp and Laravel blade when run gulp,

Do I want thing?

I want {{ asset('/') }} append to perfix URL build


head-include.blade.php Before running gulp

<!-- build:css  resources/assets/css/out.css -->
<link rel="stylesheet" href="resources/assets/css/1.css">
<link rel="stylesheet" href="resources/assets/css/2.css">
<!-- endbuild -->

gulpfiles.js

...
gulp.task('useref', function(){
  return gulp.src(paths.assets.html)
  .pipe(useref())
  .pipe(gulpIf('*.js', uglify()))

  .pipe(gulpIf('*.css', cssnano()))
  .pipe(gulp.dest(paths.dev.html))
});
...

head-include.blade.php After running gulp

<link rel="stylesheet" href="resources/assets/css/out.css">

But i want it:

i want {{ asset('/') }} append to perfix url build

head-include.blade.php I want ..

<link rel="stylesheet" href="{{ asset('/') }} resources/assets/css/out.css">

install gulp-replace

npm install gulp-replace --save-dev

replace = require('gulp-replace');

gulp.task('useref', function(){
  return gulp.src(paths.assets.view)
    .pipe(replace("{{ asset('resources/assets') }}", 'resources/assets'))
    .pipe(useref())
    // Minifies only if it's a JavaScript file
    .pipe(gulpIf('*.js', uglify()))
    // Minifies only if it's a CSS file
    .pipe(gulpIf('*.css', cssnano()))

    .pipe(gulp.dest(paths.dev.view))

    .pipe(replace('../assets', "{{ asset('resources/assets') }}"))
    .pipe(gulp.dest(paths.dev.view))
});

<!-- build:css(./)  resources/assets/css/out.css -->
<link rel="stylesheet" href="{{ asset('resources/assets') }}/css/1.css">
<link rel="stylesheet" href="{{ asset('resources/assets') }}/css/2.css">
<!-- endbuild -->

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM