Skip to content
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

Generated path in HTML not getting updated #331

Closed
petegore opened this issue Dec 2, 2022 · 2 comments
Closed

Generated path in HTML not getting updated #331

petegore opened this issue Dec 2, 2022 · 2 comments

Comments

@petegore
Copy link

petegore commented Dec 2, 2022

Hi everyone,
I installed your incredible package today, but I'm facing an issue.

I modified the base package.config.json in order to change the output dir and replace "webpack_bundles" by builds :

// /webpack.config.js
// ... imports are there
module.exports = {
 context: __dirname,
 entry: './static/app',
 output: {
   // I mainly changed this line
   path: path.resolve('./static/builds/'),
   filename: "[name]-[hash].js"
 },
 plugins: [
   new BundleTracker({filename: './webpack-stats.json'})
 ],
}

It seems this change is correctly applied when building my output assets, the path seems correct.
/webpack-stats.json

{
  "status": "done",
  "assets": {
    "main-b0a9e492033007ae27eb.js": {
      "name": "main-b0a9e492033007ae27eb.js",
      "path": "/app/static/builds/main-b0a9e492033007ae27eb.js"
    }
  },
  "chunks": {
    "main": [
      "main-b0a9e492033007ae27eb.js"
    ]
  }
}

My settings in Django are the default one provided by your tutoriel. In my case DEBUG=1 so CACHE=0 :

WEBPACK_LOADER = {
  'DEFAULT': {
    'CACHE': not DEBUG,
    'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
    'POLL_INTERVAL': 0.1,
    'IGNORE': [r'.+\.hot-update.js', r'.+\.map'],
  }
}

And in my HTML template I import the following inside my tag :

{% load render_bundle from webpack_loader %}
{% render_bundle 'main' %}

Then I build by asset by running the following command :

npx webpack --mode=development --config webpack.config.js

Bug when I run the page, I still have an old path for the script tag, resulting in a 404 error :

<script src="/static/webpack_bundles/main-b0a9e492033007ae27eb.js" ></script>

Am I missing something ? Shouldn't it be using the new path with the builds dir ?

I tried to restart the Django server, I also cleared the __pycache__ folders of all my apps. Nothing changes.

Is it a bug or a misunderstanding from me ?

Thanks a lot

@powdahound
Copy link

Also got bit by this, then found that it can be specified in the config:

'BUNDLE_DIR_NAME': 'webpack_bundles/',

@fjsj
Copy link
Member

fjsj commented Nov 29, 2023

When changing the output.path, the BUNDLE_DIR_NAME must also be updated. The bundles parent directory must also be in STATICFILES_DIRS if you're serving assets using Django's staticfiles app (which is the default in Django's runserver). Unfortunately this isn't mentioned in the README. We'll fix that. Closing as duplicate of #178

@fjsj fjsj closed this as completed Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants