diff --git a/lib/webpack/assets/public-path.js b/lib/webpack/assets/public-path.js new file mode 100644 index 0000000..1ed607c --- /dev/null +++ b/lib/webpack/assets/public-path.js @@ -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 \ No newline at end of file diff --git a/lib/webpack/entry.js b/lib/webpack/entry.js index d9e2fab..9d5fa5f 100644 --- a/lib/webpack/entry.js +++ b/lib/webpack/entry.js @@ -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)] }; } diff --git a/src/webpack/assets/public-path.js b/src/webpack/assets/public-path.js new file mode 100644 index 0000000..f774178 --- /dev/null +++ b/src/webpack/assets/public-path.js @@ -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 diff --git a/src/webpack/entry.js b/src/webpack/entry.js index 2e90dad..c2bb273 100644 --- a/src/webpack/entry.js +++ b/src/webpack/entry.js @@ -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)