2017-03-31 33 views
3

我是一個新手,我的問題是愚蠢的。Gulp:如何在生產上設置不同的基礎href

在發展我在localhost和根文件夾與gulp serve工作,如:

http://localhost:3000/

,但對生產,我想我的移動應用程序的文件夾上,如:

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

問題是index.html中的變化,dev「base href」from:

<base href="/"> 

prod

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

我可以改變我的基本href是有條件HTML註釋?例如:

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

其他技巧非常感謝!

我發現這個提示:

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

您是否找到了解決方案? –

回答

2

我有同樣的問題我自己。我寫了這個任務:

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')); 
      }); 

npm install --save-dev gulp-replace 

和排隊的生產任務的任務。

相關問題