-
Notifications
You must be signed in to change notification settings - Fork 12
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
Path of dynamic chunks is relative #42
Comments
@bluesurfer thanks for this report. Do you have an example django project you can link me to where I can see this problem occurring? I'm not fully understanding the issue and will need to be able to replicate it to fix it. Cheers. |
@shonin sorry but I am not sure that this issue is related with Anyway I will write down my progress... maybe it will help someone Consider that I am shifting my project from
I followed the basic_usage example - Webpack will create a chunk and will correctly place its path in the manifest. Unfortunately, when requested, its path is relative to the current page. For instance, if the manifest path for such chunk is I think I solve this by using a
Reference https://github.com/shellscape/webpack-manifest-plugin#compiler-hooks |
@bluesurfer, perhaps changing the |
I had the same problem which I was able to solve by updating I solved the webpack issue by changing the webpack.config.js output: {
/* This is the Django settings.STATIC_URL */
publicPath: '/static/',
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
}, I then had the issue where the STATIC_URL was being written twice by the settings.py # django-manifest-loader
# Add this *after* you define STATIC_URL
import fnmatch
from manifest_loader.loaders import LoaderABC
class ManifestLoader(LoaderABC):
static_url = STATIC_URL
@classmethod
def _get_value(cls, value):
if value.startswith(cls.static_url):
return value[len(cls.static_url) - 1 :]
return value
@classmethod
def get_single_match(cls, manifest, key):
return cls._get_value(manifest.get(key, key))
@classmethod
def get_multi_match(cls, manifest, pattern):
matched_files = [
file for file in manifest.keys() if fnmatch.fnmatch(file, pattern)
]
return [cls._get_value(manifest.get(file)) for file in matched_files]
MANIFEST_LOADER = {
"loader": ManifestLoader,
} I can see this being a reasonably common issue. In my case, I came across the issue when font files (bundled with some SCSS) were added by webpack with their relative URL - adding |
No need to write a custom loader for this. If you're using WebpackManifestPlugin, you just need to configure the webpack.config.js output: {
/* This is the Django settings.STATIC_URL */
publicPath: '/static/',
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new WebpackManifestPlugin({
publicPath: 'dist/'
})
], |
Thank you @knokit I hoped something like that would work. I tried that, but I still need a custom loader to fix the problem. If I have {
"main.js": "/static/main.123hash123.js",
"main.woff": "/static/hash123hash.woff",
"my_project/frontend/src/fonts/my-font.woff": "/static/hash123hash.woff"
} With the {% manifest_match '*.js' '<script src="{match}"></script>' %}
...outputs...
<script src="/static/static/main.123hash123.js"></script> My custom loader removes the leading {% manifest_match '*.js' '<script src="{match}"></script>' %}
...outputs...
<script src="/static/main.123hash123.js"></script> |
My previous comment was too overkill :) In my case, I finally solved this issue with the following settings: Webpack configuration
Django settings
So to me this issue is closed.. I'll let the maintainer @shonin to consider closing this. |
Thank you for the update @bluesurfer your solution fixed my issue too. Also, thank you @knokit - I made a small update and I now no longer need my custom loader. I just needed to update my new WebpackManifestPlugin({ publicPath: "" }) |
The chunks resulting from a dynamic import are incorrectly loaded into the page. Their path is relative to the page thus
causing 404 errors. To solve this I try to set the
publicPath
in Webpack config as suggested in webpack/webpack#7968Unfortunately that raises a Django
SuspiciousFileOperation
:The text was updated successfully, but these errors were encountered: