Skip to content

Commit e8f8a15

Browse files
authored
Feature/pre 1.0.4 (#45)
1 parent b7e3192 commit e8f8a15

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3251
-3580
lines changed

.github/workflows/ci.yml

-66
Original file line numberDiff line numberDiff line change
@@ -21,69 +21,3 @@ jobs:
2121
- name: Check code style
2222
run: |
2323
pre-commit run --all-files
24-
25-
test_django:
26-
runs-on: ubuntu-latest
27-
needs: [build]
28-
strategy:
29-
matrix:
30-
python-version: ['3.8', '3.9', '3.10']
31-
node-version: [18.x, 20.x]
32-
django-version: [3.2, 4.2]
33-
steps:
34-
- uses: actions/checkout@v4
35-
- name: Use Node.js ${{ matrix.node-version }}
36-
uses: actions/setup-node@v3
37-
with:
38-
node-version: ${{ matrix.node-version }}
39-
- name: Set up Python ${{ matrix.python-version }}
40-
uses: actions/setup-python@v4
41-
with:
42-
python-version: ${{ matrix.python-version }}
43-
- name: Set up Django ${{ matrix.django-version }}
44-
run: |
45-
pip install --upgrade pip
46-
pip install Django==${{ matrix.django-version }}
47-
- name: Install dependencies
48-
run: |
49-
pip install .
50-
pip install -r tests/requirements/django.txt
51-
- name: PYTHONPATH
52-
run: |
53-
echo "PYTHONPATH=${PWD}" >> $GITHUB_ENV
54-
- name: Test with pytest
55-
run: |
56-
pytest tests/tests_django
57-
58-
test_flask:
59-
runs-on: ubuntu-latest
60-
needs: [build]
61-
strategy:
62-
matrix:
63-
python-version: ['3.8', '3.9', '3.10']
64-
node-version: [18.x, 20.x]
65-
flask-version: [1.1.4, 2.2.2, 3.0.0]
66-
steps:
67-
- uses: actions/checkout@v4
68-
- name: Use Node.js ${{ matrix.node-version }}
69-
uses: actions/setup-node@v3
70-
with:
71-
node-version: ${{ matrix.node-version }}
72-
- name: Set up Python ${{ matrix.python-version }}
73-
uses: actions/setup-python@v4
74-
with:
75-
python-version: ${{ matrix.python-version }}
76-
- name: Set up Flask ${{ matrix.flask-version }}
77-
run: |
78-
pip install --upgrade pip
79-
pip install Flask==${{ matrix.flask-version }}
80-
- name: Install dependencies
81-
run: |
82-
pip install .
83-
pip install -r tests/requirements/flask.txt
84-
- name: PYTHONPATH
85-
run: |
86-
echo "PYTHONPATH=${PWD}" >> $GITHUB_ENV
87-
- name: Test with pytest
88-
run: |
89-
pytest tests/tests_flask

.pre-commit-config.yaml

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fail_fast: true
44

55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: main
7+
rev: v4.1.0
88
hooks:
99
- id: trailing-whitespace
1010
- id: end-of-file-fixer
@@ -26,10 +26,3 @@ repos:
2626
hooks:
2727
- id: flake8
2828
args: ['--config=setup.cfg']
29-
30-
# https://pre-commit.com/#regular-expressions
31-
- repo: https://github.com/prettier/pre-commit
32-
rev: v2.1.2
33-
hooks:
34-
- id: prettier
35-
types: [javascript]

docs/react.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Create `frontend/src/application/app_react.js`
5454

5555
```js
5656
import React, { useState, useEffect } from 'react';
57-
import { createRoot } from 'react-dom';
57+
import { createRoot } from 'react-dom/client';
5858

5959

6060
const Clock = () => {

docs/setup_with_django.md

+66-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Setup With Django
22

3+
We will show you how to integrate `python-webpack-boilerplate` with Django and use Tailwind v4 as the style solution.
4+
35
## Install Package
46

57
```bash
@@ -43,14 +45,20 @@ INSTALLED_APPS = [
4345

4446
Let's run Django command to create frontend project from the templates
4547

46-
```bash hl_lines="3 4"
48+
```bash
4749
$ python manage.py webpack_init
48-
49-
project_slug [frontend]:
50-
run_npm_command_at_root [y]:
51-
[SUCCESS]: Frontend app 'frontend' has been created.
50+
[1/3] project_slug (frontend):
51+
[2/3] run_npm_command_at_root (y):
52+
[3/3] Select style_solution
53+
1 - tailwind
54+
2 - bootstrap
55+
3 - scss
56+
Choose from [1/2/3] (1): 1
57+
[SUCCESS]: Frontend app 'frontend' has been created. To know more, check https://python-webpack-boilerplate.rtfd.io/en/latest/frontend/
5258
```
5359

60+
Here we use the default `Tailwind CSS` as our style solution.
61+
5462
Now a new `frontend` directory is created which contains pre-defined files for our frontend project.
5563

5664
```bash
@@ -75,9 +83,9 @@ Now a new `frontend` directory is created which contains pre-defined files for o
7583

7684
```bash
7785
$ node -v
78-
v20.10.0
86+
v22.13.1
7987
$ npm -v
80-
10.2.3
88+
10.9.2
8189
```
8290

8391
Now go to directory which contains `package.json`, by default, it is root directory.
@@ -178,39 +186,42 @@ TEMPLATES = [
178186

179187
Add `index.html` to the above `example/templates`
180188

181-
```html hl_lines="1 9 10 20"
189+
```html
182190
{% load webpack_loader static %}
183191

184192
<!DOCTYPE html>
185193
<html>
186194
<head>
187-
<meta charset="utf-8" />
188195
<title>Index</title>
189-
<script src="https://cdn.tailwindcss.com"></script>
196+
<meta charset="utf-8" />
197+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
190198
{% stylesheet_pack 'app' %}
191-
{% javascript_pack 'app' attrs='defer' %}
192199
</head>
193200
<body>
194201

195-
<div class="bg-gray-50 py-5" data-jumbotron>
196-
<div class="container mx-auto px-4 py-10">
197-
<h1 class="text-4xl font-bold leading-tight">Welcome to Our Website</h1>
198-
<p class="mt-4 text-lg">This is a hero section built using Tailwind CSS.</p>
199-
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 mt-6 rounded-lg">Get Started</button>
202+
<div class="jumbotron py-5">
203+
<div class="w-full max-w-7xl mx-auto px-4">
204+
<h1 class="text-4xl mb-4">Hello, world!</h1>
205+
<p class="mb-4">This is a template for a simple marketing or informational website. It includes a large callout called a
206+
jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
207+
208+
<p><a class="btn-blue mb-4" href="#" role="button">Learn more »</a></p>
209+
200210
<div class="flex justify-center">
201211
<img src="{% static 'vendors/images/webpack.png' %}"/>
202212
</div>
203213
</div>
204214
</div>
205215

216+
{% javascript_pack 'app' %}
217+
206218
</body>
207219
</html>
208220
```
209221

210-
1. Here we use `Tailwind CDN` to help user to do quick test, please remove it later.
211-
2. We `load webpack_loader` at the top of the template
212-
3. We can still use `static` tag to import image from the frontend project.
213-
4. We use `stylesheet_pack` and `javascript_pack` to load CSS and JS bundle files to Django
222+
1. We `load webpack_loader` at the top of the template
223+
2. We can still use `static` tag to import image from the frontend project.
224+
3. We use `stylesheet_pack` and `javascript_pack` to load CSS and JS bundle files to Django
214225

215226
!!! note
216227
1. When your javascript and css files grow bigger and bigger, code splitting would be done automatically by Webpack.
@@ -220,6 +231,9 @@ Add `index.html` to the above `example/templates`
220231
## Manual Test
221232

222233
```bash
234+
# restart webpack to let Tailwind auto scan
235+
$ npm run watch
236+
223237
$ python manage.py migrate
224238
$ python manage.py runserver
225239
```
@@ -233,7 +247,38 @@ dom ready
233247
jumbotron.js:8 Jumbotron initialized for node: [object HTMLDivElement]
234248
```
235249

236-
The source code can also be found in the [Examples](https://github.com/AccordBox/python-webpack-boilerplate/tree/master/examples/)
250+
## Explicitly Specify Source Files
251+
252+
Even Tailwind 4 can AUTO scan all project files in the project directory, we still recommend to explicitly specify the source files to improve performance.
253+
254+
Below is an example of `frontend/src/styles/index.css`
255+
256+
```css
257+
/*import tailwindcss and disable automatic source detection*/
258+
@import "tailwindcss" source(none);
259+
260+
/*register frontend directory*/
261+
@source "../";
262+
263+
/*register django templates*/
264+
@source "../../../django_tailwind_app/**/*.html";
265+
266+
.jumbotron {
267+
/*should be relative path of the entry css file*/
268+
background-image: url("../../vendors/images/sample.jpg");
269+
background-size: cover;
270+
}
271+
272+
@layer components{
273+
.btn-blue {
274+
@apply inline-flex items-center;
275+
@apply px-4 py-2;
276+
@apply font-semibold rounded-lg shadow-md;
277+
@apply text-white bg-blue-500;
278+
@apply hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-400/50;
279+
}
280+
}
281+
```
237282

238283
## Live Reload
239284

0 commit comments

Comments
 (0)