Fakultas Ilmu Komputer UI

Commit d946306d authored by Zamil Majdy's avatar Zamil Majdy
Browse files

[#140382397] #5 Add zip compression on production

parent 0c0e7ae1
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})
{% 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>
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
......@@ -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"
}
}
......@@ -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,
})
],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment