nwb build-react-app 创建根路径而不是相对路径 [英] nwb build-react-app creates root path rather than relative path

查看:73
本文介绍了nwb build-react-app 创建根路径而不是相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试 nwb 以使用此示例简化构建 React 应用程序项目.在构建应用程序时,index.html 中引用的 css 和 js 文件的路径在根目录中,而不是相对目录中.有什么办法可以改变引用吗?

例如:

在html中,引用如下,

<script type="text/javascript" src="/vendor.b3f34f12.js"></script><script type="text/javascript" src="/app.9b5c57d3.js"></script>

取而代之,

<script type="text/javascript" src="./vendor.b3f34f12.js"></script><script type="text/javascript" src="./app.9b5c57d3.js"></script>

解决方案

你可以在你的 nwb.config.js 文件中使用 webpack.publicPath :><块引用>

如果要创建与路径无关的构建,请将 publicPath 设置为空白:

module.exports = {网络包:{公共路径:''}}

来源:https://github.com/insin/nwb/blob/master/docs/Configuration.md#publicpath-string

I am testing out nwb to streamline building react apps using this example project. While the app is built, the path of css and js files referenced in index.html are in root rather than relative. Is there any way to change the referencing?

For example:

In the html, the reference are the following,

<script type="text/javascript" src="/vendor.b3f34f12.js"></script>
<script type="text/javascript" src="/app.9b5c57d3.js"></script> 

Instead of,

<script type="text/javascript" src="./vendor.b3f34f12.js"></script>
<script type="text/javascript" src="./app.9b5c57d3.js"></script> 

解决方案

You can use webpack.publicPath in your nwb.config.js file for this:

If you want to create a path-independent build, set publicPath to blank:

module.exports = {
  webpack: {
    publicPath: ''
  }
}

Source: https://github.com/insin/nwb/blob/master/docs/Configuration.md#publicpath-string

这篇关于nwb build-react-app 创建根路径而不是相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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