Skip to content

Commit 84653f3

Browse files
committed
Move swiper initialization to webpack bundle
Currently most of doccano's Javascript is in webpack bundles, except for a few snippets like swiper. To increase consistency, this change moves the swiper code also into a webpack bundle. In addition to increasing consistency, this also has the advantages of: 1) Giving developers a single location/directory to look for all the Javascript. 2) Making the swiper dependency explicit by listing it in the package.json manifest 3) Ensuring that swiper gets built and minified in the same way as other dependencies. 4) Making swiper available when developing offline. In the future, it would also be worth considering to move all the CSS includes into webpack.
1 parent ec7cf38 commit 84653f3

5 files changed

Lines changed: 41 additions & 16 deletions

File tree

app/server/package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"axios": "^0.18.0",
1515
"chart.js": "^2.7.2",
1616
"marked": "^0.3.19",
17+
"swiper": "^4.3.3",
1718
"vue": "^2.5.16",
1819
"vue-chartjs": "^3.4.0",
1920
"vue-debounce": "^1.1.0",

app/server/static/js/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Swiper from 'swiper';
2+
3+
new Swiper('.swiper-container', {
4+
// Optional parameters
5+
loop: true,
6+
autoplay: {
7+
delay: 5000,
8+
},
9+
// Navigation arrows
10+
navigation: {
11+
nextEl: '.swiper-button-next',
12+
prevEl: '.swiper-button-prev',
13+
},
14+
});

app/server/templates/index.html

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% extends "base.html" %}
22
{% load static %}
3+
{% load render_bundle from webpack_loader %}
34

45
{% block header %}
56
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.3/css/swiper.min.css">
@@ -215,19 +216,5 @@ <h2>
215216
{% endblock %}
216217

217218
{% block footer %}
218-
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.3/js/swiper.min.js"></script>
219-
<script>
220-
new Swiper('.swiper-container', {
221-
// Optional parameters
222-
loop: true,
223-
autoplay: {
224-
delay: 5000,
225-
},
226-
// Navigation arrows
227-
navigation: {
228-
nextEl: '.swiper-button-next',
229-
prevEl: '.swiper-button-prev',
230-
},
231-
})
232-
</script>
233-
{% endblock %}
219+
{% render_bundle 'index' 'js' %}
220+
{% endblock %}

app/server/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const hotReload = process.env.HOT_RELOAD === '1';
88
module.exports = {
99
mode: devMode ? 'development' : 'production',
1010
entry: {
11+
'index': './static/js/index.js',
1112
'sequence_labeling': './static/js/sequence_labeling.js',
1213
'document_classification': './static/js/document_classification.js',
1314
'seq2seq': './static/js/seq2seq.js',

0 commit comments

Comments
 (0)