Skip to content

Commit

Permalink
Merge pull request #126 from d4rkr00t/fix-img-dev-server
Browse files Browse the repository at this point in the history
fix(webpack): Images are not being loaded using webpack-dev-server
  • Loading branch information
d4rkr00t authored Nov 17, 2016
2 parents e400403 + 84f8a68 commit e97ef80
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/webpack/assets/public-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

/**
* Ugly hack which solves an issue with not loading images with generated urls in css files.
* This file loads up before entry point and dynamically sets public path to, for example, "http://localhost:4444/".
* Depends on current phost and port. And also it works well with ngrok exposed servers.
*
* Related issues: https://github.com/webpack/style-loader/pull/96
*/
__webpack_public_path__ = window.location.protocol + '//' + window.location.host + '/'; // eslint-disable-line
2 changes: 1 addition & 1 deletion lib/webpack/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function entryDev(filename, flags) {
const host = flags.host === '::' ? 'localhost' : flags.host;

return {
[entryName]: [`${ require.resolve('webpack-dev-server/client') }?http://${ host }:${ flags.port }/`, require.resolve('webpack/hot/dev-server'), (0, _resolveToCwd2.default)(filename)]
[entryName]: [require.resolve('./assets/public-path.js'), `${ require.resolve('webpack-dev-server/client') }?http://${ host }:${ flags.port }/`, require.resolve('webpack/hot/dev-server'), (0, _resolveToCwd2.default)(filename)]
};
}

Expand Down
8 changes: 8 additions & 0 deletions src/webpack/assets/public-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Ugly hack which solves an issue with not loading images with generated urls in css files.
* This file loads up before entry point and dynamically sets public path to, for example, "http://localhost:4444/".
* Depends on current phost and port. And also it works well with ngrok exposed servers.
*
* Related issues: https://github.com/webpack/style-loader/pull/96
*/
__webpack_public_path__ = window.location.protocol + '//' + window.location.host + '/'; // eslint-disable-line
1 change: 1 addition & 0 deletions src/webpack/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function entryDev(filename: string, flags: CLIFlags): Entry {

return {
[entryName]: [
require.resolve('./assets/public-path.js'),
`${require.resolve('webpack-dev-server/client')}?http://${host}:${flags.port}/`,
require.resolve('webpack/hot/dev-server'),
resolveToCwd(filename)
Expand Down

0 comments on commit e97ef80

Please sign in to comment.