加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 与webpack的动态基础href链接

发布时间:2020-12-17 17:26:57 所属栏目:安全 来源:网络整理
导读:当我转移到Angular-CLI时,我刚从systemjs转移到webpack. 它曾经工作但它不再. 这是我有的: 在我的index.html中 script type='text/javascript' var base = document.location.pathname.split('/')[1]; document.write('base href="/' + base + '" /');/scri
当我转移到Angular-CLI时,我刚从systemjs转移到webpack.
它曾经工作但它不再.
这是我有的:

在我的index.html中

<script type='text/javascript'>
    var base = document.location.pathname.split('/')[1];
    document.write('<base href="/' + base + '" />');
</script>

而且我还在添加的几个js文件的根部添加了一个“/”.

现在我在webpack上,这些文件是从其他地方加载的,我不能再添加这个“/”了.
所以它试图在http://www.exemple.com/it/xxx.js上加载它们,而不是http://www.exemple.com/xxx.js

我已经看到我必须更新webpack.config.js文件中的内容,但angular-cli家伙已经决定将它放在他们的模块中,而不是像往常一样放在项目根目录上.
我知道我可以编辑这个文件,但我不想每次更新angular-cli时再这样做.

有没有一个好方法呢?

解决方法

When building you can modify base tag () in your
index.html with –base-href your-url option.

# Sets base tag href to /myUrl/ in your index.html
ng build --base-href /myUrl/
ng build --bh /myUrl/

https://github.com/angular/angular-cli#base-tag-handling-in-indexhtml

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读