Skip to content

fix(templates): loading bootstrap files from static, discarding unused files from CDN #276 #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions djangocms_frontend/static/djangocms_frontend/css/bootstrap5.css

Large diffs are not rendered by default.

6,311 changes: 6,311 additions & 0 deletions djangocms_frontend/static/djangocms_frontend/js/bundle.bootstrap5.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions djangocms_frontend/templates/bootstrap5/base.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% extends "djangocms_frontend.html" %}{% load cms_tags menu_tags %}
{% extends "djangocms_frontend.html" %}{% load cms_tags menu_tags static %}
{% block base_css %}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<link href="{% static 'djangocms_frontend/css/bootstrap5.css' %}" rel="stylesheet">
{% endblock %}
{% block base_js %}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<script src="{% static 'djangocms_frontend/js/bundle.bootstrap5.js' %}"></script>
{% endblock %}
{% block navbar %}
<nav class="navbar {% block navbar_options %}navbar-expand-lg navbar-dark bg-dark{% endblock %}">
Expand Down
57 changes: 0 additions & 57 deletions djangocms_frontend/templates/tailwind/base.html

This file was deleted.

5 changes: 0 additions & 5 deletions djangocms_frontend/templates/tailwind/dropdown.html

This file was deleted.

26 changes: 0 additions & 26 deletions djangocms_frontend/templates/tailwind/menu.html

This file was deleted.

11 changes: 2 additions & 9 deletions docs/source/tutorial/builtin_components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,12 @@ You need to manually add them to your templates.
{% extends "bootstrap5/base.html" %}
{% block brand %}<a href="/">My Site</a>{% endblock %}

This will load Bootstrap 5 CSS and JS from a CDN.
This will load Bootstrap 5 CSS and JS.

.. note::

We recommend developing your own ``base.html`` for your projects. The
example templates load CSS and JS files from a CDN. Good reasons to do so
are
We recommend developing your own ``base.html`` for your projects.

* ``djangocms-frontend`` does not contain CSS or JS files from Bootstrap
or any other framework for that matter. The example templates load
CSS and JS from a CDN.
* It is considered safer to host CSS and JS files yourself. Otherwise you
do not have control over the CSS and/or JS that is delivered.
* It is a common practice to customize at least the CSS part, e.g. with
brand colors.
* You might have a totally different build process for your styling assets,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"stylelint-config-twbs-bootstrap": "^2.2.4",
"uglify-js": "^3.17.4",
"webpack": "^3.0.0",
"copy-webpack-plugin": "^4.6.0",
"webpack2-polyfill-plugin": "0.0.2"
}
}
87 changes: 0 additions & 87 deletions private/js/components/card-group.js

This file was deleted.

11 changes: 10 additions & 1 deletion private/js/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const argv = require('minimist')(process.argv.slice(2));
const plugins = [];
const webpack = require('webpack');
const path = require('path');
const path = require('path');1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const path = require('path');1
const path = require('path');

I assume the 1 is a typo here?

const CopyPlugin = require("copy-webpack-plugin");


process.env.NODE_ENV = (argv.debug) ? 'development' : 'production';
Expand All @@ -12,6 +13,14 @@ plugins.push(
chunks: ['base', 'grid', 'link'],
})
);
plugins.push(
new CopyPlugin([{
from: path.join(
__dirname, '..', '..', 'node_modules', 'bootstrap', 'dist', 'js', 'bootstrap.bundle.js'),
to: path.join(
__dirname, '..', '..', 'djangocms_frontend', 'static', 'djangocms_frontend', 'js', 'bundle.bootstrap5.js'),
}])
)

// add plugins depending on if we are debugging or not
if (argv.debug) {
Expand Down
3 changes: 3 additions & 0 deletions private/sass/bootstrap5.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@charset "utf-8";

@import "node_modules/bootstrap/scss/bootstrap";