Gulp: how to set different href bases to production

I'm new to Gulp (and maybe my question is stupid).

During development I work with gulp serve

in local and root folder, for example:

http: // localhost: 3000 /

but in production I want to move my application to a folder eg.

http: // localhost: 3000 / my-app /

the problem is changing index.html, dev

"base href" from:

<base href="/">

      

in prod

:

<base href="/my-app/">

      

Is it possible to change the base href with a conditional html comment? eg:.

<!-- build:dev -->
<base href="/">
<!-- endbuild -->
<!-- build:prod -->
<base href="/my-app/">
<!-- endbuild -->

      

Any other advice is greatly appreciated!

I found this advice:

return gulp.src(path.join(conf.paths.tmp, '/serve/*.html'))
        .pipe(replace('<base href="/">', '<base href="/my-app/">'))

      

+3


source to share


1 answer


I had the same problem. I wrote this task:

import gulp        from 'gulp';
import replace     from 'gulp-replace';

gulp.task('inject-base-href', function() {
   return gulp.src('path/to/your/html/file')
              .pipe(replace('<base href="/">', function(match) {
                  console.log('Replace called on', match);
                  return'<base href="/your-correct-href-path/">'
                    }
               ))
              .pipe(gulp.dest('path/to/your/build/folder'));
            });

      

and



npm install --save-dev gulp-replace

      

and set a task in production tasks.

+2


source







All Articles