Reputation: 1064
I'm trying to write a library using webpack. I'm using code splitting with require.ensure
in my main file. Problem is that it will try to resolve all chunks from base url. Is it possible to make it relative to entry-point?
For example, I add my entry-point as
<script src="node_modules/mylib/index.js">
When this file does require.ensure('./dep.js')
it will try to load /dep.js
instead of node_modules/mylib/dep.js
.
I've made a workaround by manipulating <base>
tag, but it's really an ugly hack. I feel like there should be a more "webpacky" solution.
Upvotes: 2
Views: 1570
Reputation: 26873
The key is in publicPath related settings. It can be set dynamically during runtime by using __webpack_public_path__ = window.resourceBaseUrl;
kind of declaration.
Upvotes: 4