2

I am serving my compiled app with Tomcat. The app is not served from the root context but with a suffix - e.g. mysite.com/myapp.

I need webpack to add this myapp prefix to the js and css imports in index.html.

I need this:

<html>
<head>
  <link rel="shortcut icon" href="/myapp/favicon.ico">
  <link href="/myapp/app.9c885d75239355add0ca8f22362e289c.css" rel="stylesheet">
</head>
<body>
  <div id="root"></div>
  <script src="/myapp/vendor.1c28bcf2a2efacc7d62d.js"></script>
  <script src="/myapp/app.d678b996583f01bd2f7d.js"></script>
</body>
</html>

But right now I have this:

<html>
<head>
  <link rel="shortcut icon" href="favicon.ico">
  <link href="app.9c885d75239355add0ca8f22362e289c.css" rel="stylesheet">
</head>
<body>
  <div id="root"></div>
  <script src="vendor.1c28bcf2a2efacc7d62d.js"></script>
  <script src="app.d678b996583f01bd2f7d.js"></script>
</body>
</html>

A hacky way would be to run a script during the build to change the links but I would like to have a more proper webpack solution.

I'm using HtmlWebpackPlugin and React Redux Starter Kit.

4

2 回答 2

1

output: {
  filename: '/myapp/[name].[chunkhash].js',
  ...
},
于 2016-03-23T08:20:10.957 回答
1

我想我们也可以使用Webpack publicPath

output: {
  publicPath: '/myapp/',
  ...
},
于 2020-08-25T06:49:38.247 回答