2

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.

3
  • 1
    Can you try webpack.github.io/docs/configuration.html#output-publicpath ? Commented Apr 17, 2016 at 10:49
  • It works! Please make an answer, I'll make it accepted. I needed this option: __webpack_public_path__ Commented Apr 17, 2016 at 11:54
  • Cool to hear. Added an answer. Hopefully it's clear enough. Commented Apr 17, 2016 at 12:25

1 Answer 1

4

The key is in publicPath related settings. It can be set dynamically during runtime by using __webpack_public_path__ = window.resourceBaseUrl; kind of declaration.

Sign up to request clarification or add additional context in comments.

2 Comments

So, what you are suggesting here is to set this resourceBaseUrl a global variable from the server side, so it can be used in your webpack bundle, right?
Correct. You can control it through server like that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.