Code Monkey home page Code Monkey logo

vue-django-webpack's Introduction

!!! Disclaimer: This package is not maintained and therefore is not recommended for production use. It is also recommended not to deploy a JavaScript application through Django. Please refer to load balancing with nginx or ELB/ALB and storing files on S3 or similar services.

vue-django-webpack

Vue.js and Django Web Application

  • Use of Vue.js in component form
  • Webpack building the JavaScript and CSS portions of the application
  • Django serving builds with django-webpack-loader

The advantage to this over a pure Vue.js application are those niceties included in Django's core library such as database managment and URL routing. This also includes the ability to add third party applications such as, the Django REST Framework, quickly and painfree.

Once a bundle has been created with Webpack, it can easily be served with Django's django.contrib.staticfiles app.

##Installation Setup a new Python 3 virtualenv and install the pip and npm requirements.

git clone https://github.com/djstein/vue-django-webpack.git
cd vue-django-webpack

# Virtual environment
virtualenv -p python3 venv
source venv/bin/activate

pip install -r requirements.txt
npm install

Development

During development it is useful to access the hot-load features without the need to rebuild the application. Do so by running Django in one terminal and the node server in another.

# Run Django webserver
python manage.py runserver

# Run node webserver
npm run dev

Any changes made to app/vueapp/src/ will now be seen automatically in development. Feel free to add components / new pages / etc.

Webpack Build

Local

To use the application without the use of the node server, use webpack to create a build. This will automatically switch the path needed in webpack-stats.json to reprsent the local build development bundles (.js and .css), with no changes to Django for local development.

# Local Build
npm run build

Django can continue to run while the build is recreated, however it is advised to stop the webserver and clear the browswer cache when creating new builds.

# Run Django webserver
python manage.py runserver

Production

Production Instructions Are Not Complete

For production builds, using build-proudction will pack and UglifyJS the application. IT IS RECOMMENDED TO STILL COMPLETE THE DJANGO AND VUE.JS PRODUCTION DOCUMENTATION BEFORE DEPLOYING.

# Production Build
npm run build-production

Sources

These resources were heavily referenced:

https://github.com/vuejs-templates/webpack/tree/master/template

https://github.com/owais/django-webpack-loader/tree/master/examples

Contributions

Please feel free to pull, fork, or add suggestions

vue-django-webpack's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-django-webpack's Issues

Running/Build Not rendering

Love the setup you have here, it's definitely more in depth than anything I have found yet.

So I just tried to run the application (ran two separate servers) but got these errors and wanted to see why I was getting them.

I also tried to run the production build but that didn't work as well. Any thoughts?

image

Hot Reload django template

I decided to use vue-django-webpack as a guide to understand the integrations. So I more or less manually installed all components - basically django, vue-cli and django-webpack-loader; maintaining the structure you have laid out.

Inside of the index.html django template, I see the script tag embedding app.js via localhost:8080, and all loads fine. Problem is in the console, http://localhost:8000/__webpack_hmr which is required for hot reload isn't actually running at "8000", but 8080; hence hot reload doesn't work.

It seems window.location is hardcoded into app.js, but I can imagine there's a config I can tweak to say load __webpack_hmr from localhost:8080 instead of window.location (which turns out to be localhost:8000).

I may just have missed something...kindly help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.