Skip to content

Commit 3a8e7ef

Browse files
authored
Correctly lookup assets when using a relative build directory (facebook#5163)
* Correctly lookup assets when using a relative build directory * Hah, var ... * Add e2e test for relative paths * Format svg
1 parent e595699 commit 3a8e7ef

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

config/webpack.config.prod.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
2828
// Webpack uses `publicPath` to determine where the app is being served from.
2929
// It requires a trailing slash, or the file assets will get an incorrect path.
3030
const publicPath = paths.servedPath;
31+
// Some apps do not use client-side routing with pushState.
32+
// For these, "homepage" can be set to "." to enable relative asset paths.
33+
const shouldUseRelativeAssetPaths = publicPath === './';
3134
// Source maps are resource heavy and can cause out of memory issue for large source files.
3235
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
3336
// `publicUrl` is just like `publicPath`, but we will provide it to our app
@@ -52,7 +55,13 @@ const sassModuleRegex = /\.module\.(scss|sass)$/;
5255
// common function to get style loaders
5356
const getStyleLoaders = (cssOptions, preProcessor) => {
5457
const loaders = [
55-
MiniCssExtractPlugin.loader,
58+
{
59+
loader: MiniCssExtractPlugin.loader,
60+
options: Object.assign(
61+
{},
62+
shouldUseRelativeAssetPaths ? { publicPath: '../../' } : undefined
63+
),
64+
},
5665
{
5766
loader: require.resolve('css-loader'),
5867
options: cssOptions,

0 commit comments

Comments
 (0)