Skip to content

Commit d7b4acf

Browse files
committed
add tailwind, bootstrap
1 parent 84906a0 commit d7b4acf

File tree

10 files changed

+98
-14
lines changed

10 files changed

+98
-14
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"project_slug": "frontend",
33
"run_npm_command_at_root": "y",
4-
"style_solution": ["scss"]
4+
"style_solution": ["tailwind", "bootstrap", "scss"]
55
}

webpack_boilerplate/frontend_template/hooks/post_gen_project.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,21 @@ def get_frontend_config_files():
2929
yield os.path.dirname(full_path), os.path.basename(full_path)
3030

3131

32+
def process_style_entry_file():
33+
frontend_path = os.getcwd()
34+
35+
if "{{ cookiecutter.style_solution }}".lower() == "tailwind":
36+
full_path = os.path.join(frontend_path, "src/styles/index.scss")
37+
os.remove(full_path)
38+
elif "{{ cookiecutter.style_solution }}".lower() in ["scss", "bootstrap"]:
39+
full_path = os.path.join(frontend_path, "src/styles/index.css")
40+
os.remove(full_path)
41+
42+
3243
def copy_frontend_config_files():
44+
"""
45+
Copy frontend config files to the root directory
46+
"""
3347
for dirname, filename in get_frontend_config_files():
3448
old_full_path = os.path.join(dirname, filename)
3549
root_dir = os.path.dirname(dirname)
@@ -58,6 +72,8 @@ def main():
5872
update_webpack_path()
5973
copy_frontend_config_files()
6074

75+
process_style_entry_file()
76+
6177
print_success_msg(
6278
f"Frontend app '{{ cookiecutter.project_slug }}' "
6379
f"has been created. "
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
{% if cookiecutter.style_solution == 'scss' %}
1+
{% if cookiecutter.style_solution == 'tailwind' %}
22
{
3-
"extends": "stylelint-config-standard-scss",
3+
"extends": "stylelint-config-standard",
44
"rules": {
5-
"at-rule-no-unknown": null,
6-
"scss/at-rule-no-unknown": true,
7-
"scss/at-import-partial-extension": null
5+
"at-rule-no-unknown": null
86
}
97
}
10-
{% elif cookiecutter.style_solution == 'tailwind' %}
8+
{% else %}
119
{
12-
"extends": "stylelint-config-standard",
10+
"extends": "stylelint-config-standard-scss",
1311
"rules": {
14-
"at-rule-no-unknown": null
12+
"at-rule-no-unknown": null,
13+
"scss/at-rule-no-unknown": true,
14+
"scss/at-import-partial-extension": null
1515
}
1616
}
1717
{% endif %}

webpack_boilerplate/frontend_template/{{cookiecutter.project_slug}}/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
"sass": "1.77.6",
4242
"sass-loader": "^16.0.1",
4343
"stylelint-config-standard-scss": "^14.0.0",
44+
{% elif cookiecutter.style_solution == 'tailwind' %}
45+
"tailwindcss": "^4.0.3",
46+
"@tailwindcss/postcss": "^4.0.3",
47+
{% elif cookiecutter.style_solution == 'bootstrap' %}
48+
"sass": "1.77.6",
49+
"sass-loader": "^16.0.1",
50+
"stylelint-config-standard-scss": "^14.0.0",
51+
"bootstrap": "^5.3.3",
4452
{% endif %}
4553
"style-loader": "^4.0.0",
4654
"stylelint": "^16.14.1",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
{% if cookiecutter.style_solution == 'tailwind' %}
2+
module.exports = {
3+
plugins: {
4+
"@tailwindcss/postcss": {},
5+
}
6+
}
7+
{% else %}
18
const postcssPresetEnv = require("postcss-preset-env");
29

310
module.exports = {
411
plugins: [postcssPresetEnv()],
512
};
13+
{% endif %}

webpack_boilerplate/frontend_template/{{cookiecutter.project_slug}}/src/application/app.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// This is the scss entry file
1+
{% if cookiecutter.style_solution == 'scss' %}
2+
// This is the style entry file
23
import "../styles/index.scss";
34

45
// We can import other JS file as we like
@@ -12,3 +13,36 @@ window.document.addEventListener("DOMContentLoaded", function () {
1213
new Jumbotron(elem);
1314
}
1415
});
16+
{% elif cookiecutter.style_solution == 'tailwind' %}
17+
// This is the style entry file
18+
import "../styles/index.css";
19+
20+
// We can import other JS file as we like
21+
import Jumbotron from "../components/jumbotron";
22+
23+
window.document.addEventListener("DOMContentLoaded", function () {
24+
window.console.log("dom ready");
25+
26+
// Find elements and initialize
27+
for (const elem of document.querySelectorAll(Jumbotron.selector())) {
28+
new Jumbotron(elem);
29+
}
30+
});
31+
{% elif cookiecutter.style_solution == 'bootstrap' %}
32+
// This is the style entry file
33+
import "../styles/index.scss";
34+
35+
import "bootstrap/dist/js/bootstrap.bundle";
36+
37+
// We can import other JS file as we like
38+
import Jumbotron from "../components/jumbotron";
39+
40+
window.document.addEventListener("DOMContentLoaded", function () {
41+
window.console.log("dom ready");
42+
43+
// Find elements and initialize
44+
for (const elem of document.querySelectorAll(Jumbotron.selector())) {
45+
new Jumbotron(elem);
46+
}
47+
});
48+
{% endif %}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
{% if cookiecutter.style_solution == 'bootstrap' %}
2+
// If you comment out code below, bootstrap will use red as primary color
3+
// and btn-primary will become red
4+
5+
// $primary: red;
6+
7+
@import "~bootstrap/scss/bootstrap";
8+
19
.jumbotron {
210
// should be relative path of the entry scss file
311
background-image: url("../../vendors/images/sample.jpg");
412
background-size: cover;
513
}
14+
{% elif cookiecutter.style_solution == 'scss' %}
15+
.jumbotron {
16+
// should be relative path of the entry scss file
17+
background-image: url("../../vendors/images/sample.jpg");
18+
background-size: cover;
19+
}
20+
{% endif %}

webpack_boilerplate/frontend_template/{{cookiecutter.project_slug}}/webpack/webpack.config.dev.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ module.exports = merge(common, {
6565
},
6666
},
6767
"postcss-loader",
68-
{% if cookiecutter.style_solution == 'scss' %}
68+
{% if cookiecutter.style_solution == 'tailwind' %}
69+
{% else %}
6970
"sass-loader",
7071
{% endif %}
7172
],

webpack_boilerplate/frontend_template/{{cookiecutter.project_slug}}/webpack/webpack.config.prod.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ module.exports = merge(common, {
3333
MiniCssExtractPlugin.loader,
3434
"css-loader",
3535
"postcss-loader",
36-
{% if cookiecutter.style_solution == 'scss' %}
37-
"sass-loader",
36+
{% if cookiecutter.style_solution == 'tailwind' %}
37+
{% else %}
38+
"sass-loader",
3839
{% endif %}
3940
],
4041
},

webpack_boilerplate/frontend_template/{{cookiecutter.project_slug}}/webpack/webpack.config.watch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ module.exports = merge(common, {
5353
},
5454
},
5555
"postcss-loader",
56-
{% if cookiecutter.style_solution == 'scss' %}
56+
{% if cookiecutter.style_solution == 'tailwind' %}
57+
{% else %}
5758
"sass-loader",
5859
{% endif %}
5960
],

0 commit comments

Comments
 (0)