[英]Gulp: how set different base href on production
i'm a newbie on Gulp (and maybe my question is stupid). 我是Gulp的新手(也许我的问题很愚蠢)。
On development i work with a gulp serve
on localhost and root folder, eg: 在开发中,我使用localhost和root文件夹上的
gulp serve
,例如:
http://localhost:3000/ HTTP://本地主机:3000 /
but on production i want move my app on a folder, eg.: 但在生产中,我想在一个文件夹上移动我的应用程序,例如:
http://localhost:3000/my-app/ HTTP://本地主机:3000 /我的应用程序内/
the problem is change in the index.html, the dev
"base href" from: 问题是index.html中的变化,
dev
“base href”来自:
<base href="/">
to the prod
: 对于
prod
:
<base href="/my-app/">
can i change my base href with a conditional html comment? 我可以用条件html注释更改我的基本href吗? eg.:
例如。:
<!-- build:dev -->
<base href="/">
<!-- endbuild -->
<!-- build:prod -->
<base href="/my-app/">
<!-- endbuild -->
Any other tips is very appreciated! 非常感谢任何其他提示!
I have found this tip: 我找到了这个提示:
return gulp.src(path.join(conf.paths.tmp, '/serve/*.html'))
.pipe(replace('<base href="/">', '<base href="/my-app/">'))
I had the same problem myself. 我自己也有同样的问题。 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 queued the task in production tasks. 并将任务排入生产任务中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.