diff --git a/core/apps.py b/core/apps.py index 2a226bf1627f306ee4469cf41b67ff818931c3a0..a4d8875cf879a32703bf6fb57db5061aabd35171 100644 --- a/core/apps.py +++ b/core/apps.py @@ -1,5 +1,6 @@ from django.shortcuts import render from django.apps import AppConfig +from kape.settings import RUNNING_DEVSERVER class CoreConfig(AppConfig): @@ -8,4 +9,4 @@ class CoreConfig(AppConfig): # Create your views here. def index(request): - return render(request, 'core/index.html') + return render(request, 'core/index.html', context={'is_devserver': RUNNING_DEVSERVER}) diff --git a/core/templates/core/index.html b/core/templates/core/index.html index 83929f4945ce1a06da67f92d43877b705969116f..373e53a7fd37270c08e033967f4e4b44f740adfd 100644 --- a/core/templates/core/index.html +++ b/core/templates/core/index.html @@ -1,5 +1,6 @@ {% load render_bundle from webpack_loader %} {% load static from staticfiles %} + <!DOCTYPE html> <html> <head> @@ -12,6 +13,10 @@ <body> <div id="react-app"></div> - {% render_bundle 'main' 'js' 'DEFAULT' attrs='async defer="true"' %} + {% if is_devserver %} + {% render_bundle 'main' 'js' 'DEFAULT' attrs='async defer="true"' %} + {% else %} + {% render_bundle 'main' 'js.gz' 'DEFAULT' attrs='async defer="true"' %} + {% endif %} </body> </html> diff --git a/kape/settings.py b/kape/settings.py index 2ecbfaef5b852105db6a15cee285fa5e527d5ae5..5b8d102bbcc114638ab9fcac947ed4376c461eb5 100644 --- a/kape/settings.py +++ b/kape/settings.py @@ -1,4 +1,5 @@ import os +import sys BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -150,3 +151,5 @@ GZIP_CONTENT_TYPES = ( ) SESSION_COOKIE_HTTPONLY = False + +RUNNING_DEVSERVER = (len(sys.argv) > 1 and sys.argv[1] == 'runserver') \ No newline at end of file diff --git a/package.json b/package.json index 833491383134e89108973b3046cb85462977bcb0..2760aed90deedd0dad31a786e7a2b59b8ad127ec 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "description": "", "main": "index.js", "scripts": { - "build": "webpack --config webpack.config.js --progress --colors", - "build-production": "webpack --config webpack.prod.config.js --progress --colors", - "webpack": "webpack --progress --display-error-details --config webpack.config.js --watch", + "build": "webpack --config webpack.prod.config.js --progress --colors", + "build-production": "webpack --config webpack.prod.config.js --progress --colors && sed -i 's/js/js.gz/g' webpack-stats.json", + "webpack": "webpack -p --progress --display-error-details --config webpack.config.js --watch", "watch": "node server.js", "karma": "karma start" }, @@ -44,7 +44,6 @@ "react-dom": "^15.4.1", "react-router": "^3.0.2", "react-tap-event-plugin": "^2.0.1", - "semantic-ui-css": "^2.2.9", "semantic-ui-react": "^0.65.0" } } diff --git a/webpack.prod.config.js b/webpack.prod.config.js index 741153f4649ecbc8161ce35bf0753b47866cd33e..f84091c191454a433f448a1307d341bf75447910 100644 --- a/webpack.prod.config.js +++ b/webpack.prod.config.js @@ -10,7 +10,7 @@ module.exports = { output: { path: path.resolve('./assets/bundles/'), - filename: "[name]-[hash].js", + filename: "[name]-[hash].js" }, plugins: [ @@ -27,6 +27,7 @@ module.exports = { new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.DedupePlugin(), new webpack.optimize.UglifyJsPlugin({ + minimize : true, mangle: true, compress: { warnings: false, // Suppress uglification warnings @@ -48,7 +49,8 @@ module.exports = { algorithm: "gzip", test: /\.js$|\.css$|\.html$/, threshold: 10240, - minRatio: 0.8 + minRatio: 0.8, + deleteOriginalAssets: true, }) ],