-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
__webpack_public_path__
does not work if entrypoint uses ES6-style imports
#2776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
ES6 says that
They are always treated as though you had the second version. This is part of the ES6 spec and has nothing to do with Webpack. Since the import statement will occur before the assignment to Therefore, your desired behavior would require you to use |
@harmony7 ohh, didn't even think that hoisting could be the root cause of that problem, thanks for the tip! To have symmetry with the |
One way you can work around this (sort of) is like this: main.js
entry.js
Use entry.js as your webpack entry point. If you want to use |
@harmony7 yea that's what I'm currently doing (thanks for the suggestion though!), it's not the prettiest solution as it means I need to create separate files for each of my entrypoints that uses Broken symmetry/intuition in build tools IMO warrants an eventual solution |
// entry.js
import "./public-path.js"
import "app"; // public-path.js
__webpack_public_path__ = "..." |
@sokra (just a clarification) is that always guaranteed to work, or just a quirk of how webpack builds the imports? |
I think this should be guaranteed by the ES6 spec. |
I've found that you can load the public-path.js file in @sokra 's example by adding to the entry array in webpack.config.js. Then it's much less intrusive.
|
Is it worth defining a plugin extension point to allow developers to reprogram how public paths are computed, for cases where the config file default isn't sufficient? I wanted this in the context of Aerobatic, where an HTML preprocessor outside of my control modifies my pages to add a CDN base URL as a global variable, well after webpack has finished running. |
@ojacobson i bumped into the same problem and drafted this solution |
Am I wrong to think that this would be much simpler if |
This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Issue was closed because of inactivity. If you think this is still a valid issue, please file a new issue with additional information. |
window.webpack_public_path why not use |
- to read from the back-end's set public path to be set in template - add publicPath to all entrypoints first so that it occurs before the ES6 module hoisting of any entrypoint - see also webpack/webpack#2776
For anyone making a lib consumed by other app and who wants to set public path at runtime via options passed from consumer to lib, here is what i ended up doing
|
I've tried all this suggestion and others but none of them are working for me. I have a similar problem, where i need to load mu chunks from a different origin. Currently using CRA -create-react-app-, i have in my entry file:
in
Am i missing something? |
@rrubiorr81 Did you solved it ? |
this is not working in my case. path is not setting for image and css files |
Hi. |
I'm submitting a bug report
Webpack version: 1.13.1
Please tell us about your environment: Ubuntu 14.04
Current behavior:
Entrypoint file:
If I use
import 'navbar/navbar.es6'
instead, the images that are loaded inside ofnavbar.es6
(viaimport imageName from 'img/filepath.png'
) do not have the public_path prepended to them. When I use the aboverequire('navbar/navbar.es6')
, it works fine. CommonJS imports work but ES6-style ones do not when dynamically setting__webpack_public_path__
Expected/desired behavior:
There should be no difference between ES6 and CommonJS modules
The text was updated successfully, but these errors were encountered: