设置不同的 <base> 的正确方法是什么?用于开发/登台/生产 [英] What is the right way to set a different <base> for dev/staging/production

查看:24
本文介绍了设置不同的 <base> 的正确方法是什么?用于开发/登台/生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<base href="">

对于开发和生产是不同的(对于生产它是子文件夹).使用 webpack 构建不同基础的好方法是什么?

for dev and production are different(for production it's subfolder). What is the good way to build different base with webpack?

推荐答案

目前我发现最好的方法是将此属性放在 config(HtmlWebpackPlugin option) 中:

the best what I found so far was to put this property in config(HtmlWebpackPlugin option):

new HtmlWebpackPlugin({
  ...
  baseUrl: process.env.NODE_ENV == 'development'?'/':'/app/'
})

然后在index.html中输出:

and then output it in index.html:

<base href="<%= htmlWebpackPlugin.options.baseUrl %>" />

这篇关于设置不同的 &lt;base&gt; 的正确方法是什么?用于开发/登台/生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆