Skip to content

Commit

Permalink
Replace django-compress with webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
apardyl committed Nov 30, 2020
1 parent 2919d41 commit 0bd6bfa
Show file tree
Hide file tree
Showing 65 changed files with 1,537 additions and 66 deletions.
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
last 2 versions
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ dmypy.json
.idea/
/media/
/static/
assets/webpack_bundles/
node_modules/
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ pip install -r requirements.txt
python manage.py migrate
python manage.py sync_page_translation_fields
python manage.py update_translation_fields
python manage.py runserver
yarn install
yarn dev && python manage.py runserver
```
### (alternative) setup with PyCharm
* (from start screen) `Get from version control`
Expand All @@ -28,6 +29,8 @@ pip install -r requirements.txt
python manage.py migrate
python manage.py sync_page_translation_fields
python manage.py update_translation_fields
yarn install
yarn dev &
```
* Click on the `manage.py`, PyCharm should reindex the project
* `Add Configuration...` -> `+` -> `Django Server` -> `OK`
Expand Down
3 changes: 1 addition & 2 deletions agenda/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class EventIndexBlock(StructBlock):

def get_context(self, value, parent_context=None):
context = super().get_context(value, parent_context)
context['posts'] = Event.objects.live().public() \
.descendant_of(value['index']).order_by('-date')[
context['posts'] = Event.objects.live().public().descendant_of(value['index']).order_by('-date')[
:value['shown_posts']]
return context

Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 22 additions & 25 deletions common/templates/common/base.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load webpack_loader %}
{% load wagtailcore_tags %}
{% load i18n %}
{% load static wagtailuserbar %}
{% load compress %}
{% get_current_language as LANGUAGE_CODE %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE }}">
Expand All @@ -11,24 +11,22 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

{% compress css %}
<link rel="stylesheet" type="text/x-scss" href="{% static 'common/scss/main.scss' %}">
{% endcompress %}
{% render_bundle 'css' 'css' %}

<link rel="apple-touch-icon" sizes="180x180" href="{% static 'common/favicon/apple-touch-icon.png' %}">
<link rel="icon" type="image/png" sizes="32x32" href="{% static 'common/favicon/favicon-32x32.png' %}">
<link rel="icon" type="image/png" sizes="16x16" href="{% static 'common/favicon/favicon-16x16.png' %}">
<link rel="manifest" href="{% static 'common/site.webmanifest' %}">
<link rel="mask-icon" href="{% static 'common/favicon/safari-pinned-tab.svg' %}" color="#333a6d">
<link rel="shortcut icon" href="{% static 'common/favicon/favicon.ico' %}">
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'favicon/apple-touch-icon.png' %}">
<link rel="icon" type="image/png" sizes="32x32" href="{% static 'favicon/favicon-32x32.png' %}">
<link rel="icon" type="image/png" sizes="16x16" href="{% static 'favicon/favicon-16x16.png' %}">
<link rel="manifest" href="{% static 'site.webmanifest' %}">
<link rel="mask-icon" href="{% static 'favicon/safari-pinned-tab.svg' %}" color="#333a6d">
<link rel="shortcut icon" href="{% static 'favicon/favicon.ico' %}">
<meta name="apple-mobile-web-app-title" content="{% trans 'SFI IT Academic Festival' %}">
<meta name="application-name" content="{% trans 'SFI IT Academic Festival' %}">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-config" content="{% static 'common/browserconfig.xml' %}">
<meta name="msapplication-config" content="{% static 'browserconfig.xml' %}">
<meta name="theme-color" content="#333a6d">

{% block head %}
<title>{% trans 'SFI IT Academic Festival' %}</title>
<title>{% trans 'SFI IT Academic Festival' %}</title>
{% endblock %}

<!-- temporary, just for developlment purposes-->
Expand All @@ -37,23 +35,22 @@
</head>

<body>
{% wagtailuserbar %}
{% wagtailuserbar %}

<div class="content">
{% include 'common/partials/navbar.html' %}
{% include 'common/partials/header.html' %}
<main>
{% block content %}
{% endblock content %}
</main>
</div>
<div class="content">
{% include 'common/partials/navbar.html' %}
{% include 'common/partials/header.html' %}
<main>
{% block content %}
{% endblock content %}
</main>
</div>


{% include 'common/partials/footer.html' %}
{% include 'common/partials/footer.html' %}

{% render_bundle 'js' 'js' %}

{% compress js %}
<script type="text/javascript" src="{% static 'common/js/main.js' %}"></script>
{% endcompress %}
</body>

</html>
10 changes: 5 additions & 5 deletions common/templates/common/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ <h2>{% trans 'Contact us' %}</h2>
<div class="footer__orgs">
<a href="https://ksi.ii.uj.edu.pl/" target="_blank" rel="noopener" title="Koło Studentów Informatyki UJ"
class="footer__orgs__single">
<img src="{% static 'common/img/orgs/logo-ksi.svg' %}" alt="KSI UJ logo">
<img src="{% static 'img/orgs/logo-ksi.svg' %}" alt="KSI UJ logo">
</a>
<a href="https://www.facebook.com/knbit" target="_blank" rel="noopener" title="Koło Naukowe BIT AGH"
class="footer__orgs__single">
<img src="{% static 'common/img/orgs/logo-bit.svg' %}" alt="BIT AGHlogo">
<img src="{% static 'img/orgs/logo-bit.svg' %}" alt="BIT AGHlogo">
</a>
<a href="https://www.facebook.com/KNIUEK" target="_blank" rel="noopener" title="Koło Naukowe i::team UEK"
class="footer__orgs__single">
<img src="{% static 'common/img/orgs/logo-iteam.svg' %}" alt="iTEAM UEKlogo">
<img src="{% static 'img/orgs/logo-iteam.svg' %}" alt="iTEAM UEKlogo">
</a>
<a href="https://www.facebook.com/KniOnPk/" target="_blank" rel="noopener" title="Koło Naukowe Informatyki PK"
class="footer__orgs__single">
<img src="{% static 'common/img/orgs/logo-pk.svg' %}" alt="KNII PK logo">
<img src="{% static 'img/orgs/logo-pk.svg' %}" alt="KNII PK logo">
</a>
<a href="https://www.academica.org.pl/" target="_blank" rel="noopener"
title="Fundacja Studentów i Absolwentów AGH w Krakowie ACADEMICA" class="footer__orgs__single">
<img src="{% static 'common/img/orgs/logo-aca.svg' %}" alt="ACADEMICA logo">
<img src="{% static 'img/orgs/logo-aca.svg' %}" alt="ACADEMICA logo">
</a>
</div>
<div class="footer__copyright">
Expand Down
6 changes: 3 additions & 3 deletions common/templates/common/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<nav class="navbar">
<a class="navbar__logo" href="{% slugurl_trans 'home' %}">
<picture>
<source srcset="{% static 'common/img/logo.webp' %}" type="image/webp">
<img src="{% static 'common/img/logo.png' %}" alt="sfi logo">
<source srcset="{% static 'img/logo.webp' %}" type="image/webp">
<img src="{% static 'img/logo.png' %}" alt="sfi logo">
</picture>
</a>

Expand All @@ -26,7 +26,7 @@
{% if page and lang != lang_code %}
{% language lang_code %}
<a class="navbar__link" href="{{ page.url }}">
{% with lang_icon='common/img/icon-'|add:lang_code|add:'.png' lang_icon_webp='common/img/icon-'|add:lang_code|add:'.webp' %}
{% with lang_icon='img/icon-'|add:lang_code|add:'.png' lang_icon_webp='img/icon-'|add:lang_code|add:'.webp' %}
<picture>
<source srcset="{% static lang_icon_webp %}" type="image/webp">
<img class="navbar__image" src="{% static lang_icon %}"
Expand Down
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "wwwsfi",
"version": "1.0.0",
"main": "index.js",
"repository": "https://git.sfi.pl/scm/www/wwwsfi.git",
"author": "SFI IT Academic Festival <[email protected]>",
"license": "MIT",
"private": true,
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production"
},
"devDependencies": {
"autoprefixer": "^10.0.4",
"browserslist": "^4.14.7",
"css-loader": "^5.0.1",
"file-loader": "^6.2.0",
"mini-css-extract-plugin": "^1.3.1",
"postcss": "^8.1.10",
"postcss-loader": "^4.1.0",
"sass": "^1.29.0",
"sass-loader": "^10.1.0",
"style-loader": "^2.0.0",
"webpack": "^5.9.0",
"webpack-bundle-tracker": "^0.4.3",
"webpack-cli": "^4.2.0"
}
}
5 changes: 5 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
plugins: {
autoprefixer: {}
}
}
6 changes: 1 addition & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
Django>=3.1.2,<3.2
wagtail>=2.10.2,<2.11
-e git+https://github.com/sfikrakow/django-sfibase.git@5dfb2f269c791144304ac433f8aa4d03a9b9ac7c#egg=django_sfibase
django_compressor>=2.4,<2.5
django-libsass==0.8
Brotli>=1.0.9,<1.1
beautifulsoup4<4.9,>=4.8
closure==20191111
django-modeltranslation>=0.15.2,<0.16
wagtail-modeltranslation>=0.10.14,<0.11.0
django-livereload-server==0.3.2
django-redis>=4.12.1,<4.13
numpy>=1.19.2,<1.20
opencv-contrib-python-headless>=4.4.0.44,<4.4.1
django-recaptcha==2.0.6
django-webpack-loader==0.7.0
38 changes: 13 additions & 25 deletions sfi_www/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@
]

THIRD_PARTY_APPS = [
'compressor',
'sfi_base',
'wagtail_modeltranslation',
'wagtail_modeltranslation.makemigrations',
'wagtail_modeltranslation.migrate',
'livereload',
'captcha'
'captcha',
'webpack_loader'
]

MY_APPS = [
Expand Down Expand Up @@ -176,11 +176,10 @@
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
]

STATICFILES_DIRS = [
# os.path.join(PROJECT_DIR, 'static'),
os.path.join(BASE_DIR, 'assets'),
]

# ManifestStaticFilesStorage is recommended in production, to prevent outdated
Expand All @@ -191,29 +190,18 @@
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

COMPRESS_FILTERS = {
'css': [
'compressor.filters.css_default.CssAbsoluteFilter',
'compressor.filters.cssmin.rCSSMinFilter',
],
'js': [
# 'compressor.filters.closure.ClosureCompilerFilter', # TODO: enable it after fixing globals.
],
WEBPACK_LOADER = {
'DEFAULT': {
'CACHE': not DEBUG,
'BUNDLE_DIR_NAME': 'webpack_bundles/', # must end with slash
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
'POLL_INTERVAL': 0.1,
'TIMEOUT': None,
'IGNORE': [r'.+\.hot-update.js', r'.+\.map'],
'LOADER_CLASS': 'webpack_loader.loader.WebpackLoader',
}
}

COMPRESS_PRECOMPILERS = (
('text/x-scss', 'django_libsass.SassCompiler'),
)

COMPRESS_OFFLINE = True

COMPRESS_STORAGE = 'compressor.storage.GzipCompressorFileStorage'
COMPRESS_CLOSURE_COMPILER_BINARY = '/usr/bin/env closure'
COMPRESS_CLOSURE_COMPILER_ARGUMENTS = '--compilation_level=WHITESPACE_ONLY --warning_level=VERBOSE ' \
'--summary_detail_level=3 --language_out=ECMASCRIPT5_STRICT'
COMPRESS_CSS_HASHING_METHOD = 'content'
COMPRESS_OUTPUT_DIR = 'min'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

Expand Down
1 change: 1 addition & 0 deletions webpack-stats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"status":"done","publicPath":"/static/webpack_bundles/","chunks":{"js":[{"name":"js-a7548d7674df88236a0a.js","publicPath":"/static/webpack_bundles/js-a7548d7674df88236a0a.js","path":"/home/adam/PycharmProjects/wwwsfi/assets/webpack_bundles/js-a7548d7674df88236a0a.js"}],"css":[{"name":"css-a7548d7674df88236a0a.css","publicPath":"/static/webpack_bundles/css-a7548d7674df88236a0a.css","path":"/home/adam/PycharmProjects/wwwsfi/assets/webpack_bundles/css-a7548d7674df88236a0a.css"},{"name":"css-a7548d7674df88236a0a.js","publicPath":"/static/webpack_bundles/css-a7548d7674df88236a0a.js","path":"/home/adam/PycharmProjects/wwwsfi/assets/webpack_bundles/css-a7548d7674df88236a0a.js"}]}}
42 changes: 42 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const path = require('path');
const webpack = require('webpack');
const BundleTracker = require('webpack-bundle-tracker');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
context: __dirname,
entry: {
js: './assets/js/main.js',
css: './assets/sass/main.scss'
},
output: {
path: path.resolve('./assets/webpack_bundles/'),
publicPath: "/static/webpack_bundles/",
filename: "[name]-[hash].js"
},
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{loader: 'css-loader', options: {sourceMap: true}},
'postcss-loader',
'sass-loader'
]
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
},
],
},
]
},
plugins: [
new BundleTracker({filename: './webpack-stats.json'}),
new MiniCssExtractPlugin({filename: "[name]-[hash].css"})
]
}
Loading

0 comments on commit 0bd6bfa

Please sign in to comment.