-
-
Notifications
You must be signed in to change notification settings - Fork 256
How to deal with relative public path #46
Comments
Why don't you set it to |
Because I want to use these files in cordova app, using '/' will fail. |
yeah same issue here @adcentury any progress? |
It isn't a very good solution but you can work around this issue by placing the scripts and css in the www folder with the index.html and setting |
@export-mike The only way I found is to put all files (include html, js, css, images) into the www folder as @dancoates said. By the way, |
Are you using these in a separate app? If so, have you tried setting up your webpack dev server to proxy the other app, that way you can use '/' as your publicPath base but still forward requests to other app e.g. var buildPath = '/wp-content/themes/mytheme/build/';
var config = {
entry: [
'webpack-dev-server/client?http://localhost:8080/',
'webpack/hot/only-dev-server',
path.join(__dirname, 'src/index.js')
],
output: {
path: path.resolve(__dirname, 'wp-content/themes/tpbc/build'),
filename: 'index.js',
publicPath: buildPath
},
devtool: 'eval-source-map',
resolve: { alias: {} },
devServer: {
contentBase: buildPath,
proxy: {
'*': {
target: externalServerURL,
bypass: function(req) {
// Make sure that non-webpack assets have the correct host header so any vhost works correctly.
if (req.headers && req.headers.accept) {
// Detect requests that do not contain the build directory
if (req.url.indexOf(buildPath) === -1) {
req.headers.host = externalServerURL.split('/')[2];
}
}
}
}
}
}, |
@mummybot at least in my case the other app is a cordova iphone app, so proxying is not an option. The core of the problem is that CSS loads assets relative to itself, and js loads assets relative to the HTML. So if the CSS isn't in the same place as the HTML then you can't use relative paths. It would be good to be able to pass a resolving function to the file loader to allow more complex path resolution. |
I meet the same problem,do someone knows how to deal with it now? |
Hello. I have faced the same problem trying to pack my web app as "native" ios/android application with Cordova. In my specific case it's a React application with react-router. Web version uses HTML5 History API, so basic relative paths for assets are not work correctly on pages other than "/". But if you use Hash History instead of HTML5 History (which is by the way is recommended for cordova applications, you don't see urls anyway) it seems to work fine. For more information see this thread: remix-run/react-router#2161 So if it's your case you can set publicPath in webpack config to empty string (so you'll get relative paths) and use Hash History with your router. |
I have a config that's working with Cordova and code push I can share with On Thu, 16 Jun 2016, 12:43 Ilya Gutsalyuk, [email protected] wrote:
|
@export-mike can you post that config? |
I'm having the same problem, not using react but vuejs + cordova. I tried to setting:
However the resulting cordova index.html file still ends up with entries like:
My hacky fix is to just write a little shell script (there is probably a proper webpack post-hook way of doing this but I dunno what it is) to replace all instances of I crave a better solution, emailed @export-mike to see if he can share his config with us. Edit: Welp actually I'm a dork. The webpack template I'm using has separate sections for When I set it for production like:
I got this kind of output in cordova's index.html file:
Which works fine in Cordova and when I tested in iOS simulator. |
Is there a solution for this now? |
^ bump. The issue I'm having is using vue.js with webpack. I bind a html tag like this: when the client renders the page, the src path is correct, however it is the actual relative path (e.g. "../assets/example.png" etc, instead of the path webpack outputs. Thus, the image creates a 404 because there is no image at "../assets/example.png". Alternatively, if i hardcode the src |
I fix it partially with "url-loader", It generate data:image/png;base64
I replace file-loader with url-loader. My Webpack.config.js dev mode
Other alternative with sass/scss using extract-text-webpack-plugin
|
I believe I'm also suffering from the same issue and the above gives me:
|
I'm using My CSS and JS is loading correctly from the CDN environment I upload them to and point towards with If I, however, use Is |
@prewk I ran into the same problem, webpack/webpack#971 had the clue that got it working for me. Add a new entry before your other ones and modify |
Thanks, that's exactly how I'm setting it at the moment, though. I ended up not using the |
Is there a solution for this now? v1 or v2 |
closed in #135 and available in |
For those reading who are using |
I have solved my problem with the following
I think you can do the same with You can also do |
I set a relative public path in outputs
Then the file structure is like
When i require image in css, i works fine.
But when i require image in some js, the url is wrong.
Any one can help me with it? Thanks.
The text was updated successfully, but these errors were encountered: