Browse Source

Webpack

master
Dylan Baker 5 years ago
parent
commit
b96a766357
14 changed files with 9413 additions and 134 deletions
  1. 2
    0
      .gitignore
  2. 1
    0
      Pipfile
  3. 8
    1
      Pipfile.lock
  4. 8
    0
      assets/js/index.js
  5. 122
    0
      assets/scss/style.scss
  6. 1
    0
      manifest.json
  7. 9179
    0
      package-lock.json
  8. 25
    0
      package.json
  9. 52
    0
      webpack.config.js
  10. 13
    1
      yird/app.py
  11. 0
    0
      yird/static/.gitkeep
  12. 0
    122
      yird/static/css/style.css
  13. 0
    8
      yird/static/js/index.js
  14. 2
    2
      yird/templates/layout.html.j2

+ 2
- 0
.gitignore View File

@@ -1,2 +1,4 @@
1 1
 *.egg-info
2 2
 .pytest_cache
3
+yird/static/*.css
4
+yird/static/*.js

+ 1
- 0
Pipfile View File

@@ -12,6 +12,7 @@ gitpython = "*"
12 12
 markdown = "*"
13 13
 pytest = "*"
14 14
 pytest-cov = "*"
15
+flask-webpack = "*"
15 16
 
16 17
 [requires]
17 18
 python_version = "3.7"

+ 8
- 1
Pipfile.lock View File

@@ -1,7 +1,7 @@
1 1
 {
2 2
     "_meta": {
3 3
         "hash": {
4
-            "sha256": "c37bdd943d5c3cbb47764bbad66de712f10e5eddea7273ca31240f906d380677"
4
+            "sha256": "4389fadf9b02e4cf8b8de26830e9ffa003e4414fe29778e11d1a07862e19c8da"
5 5
         },
6 6
         "pipfile-spec": 6,
7 7
         "requires": {
@@ -81,6 +81,13 @@
81 81
             "index": "pypi",
82 82
             "version": "==1.0.2"
83 83
         },
84
+        "flask-webpack": {
85
+            "hashes": [
86
+                "sha256:aa56bf97253a07e09514e2ff6ff67497d8654a66a17c208394687a64528ddc74"
87
+            ],
88
+            "index": "pypi",
89
+            "version": "==0.1.0"
90
+        },
84 91
         "gitdb2": {
85 92
             "hashes": [
86 93
                 "sha256:83361131a1836661a155172932a13c08bda2db3674e4caa32368aa6eb02f38c2",

+ 8
- 0
assets/js/index.js View File

@@ -0,0 +1,8 @@
1
+document.querySelector('[data-generate-button]').addEventListener('click',
2
+  function (e) {
3
+    var r = confirm('Are you sure? This will overwrite any existing content.');
4
+    if (!r) {
5
+      e.preventDefault();
6
+    }
7
+  }
8
+);

+ 122
- 0
assets/scss/style.scss View File

@@ -0,0 +1,122 @@
1
+/* global */
2
+
3
+* {
4
+  box-sizing: border-box;
5
+  margin: 0;
6
+  padding: 0;
7
+}
8
+
9
+ul {
10
+  list-style: none;
11
+}
12
+
13
+a {
14
+  text-decoration: none;
15
+}
16
+
17
+.heading {
18
+  border-bottom: 1px solid #000000;
19
+  font-size: 24px;
20
+  margin-bottom: 15px;
21
+}
22
+
23
+/* layout */
24
+
25
+.container {
26
+  display: flex;
27
+}
28
+
29
+.main {
30
+  display: flex;
31
+  flex: 1;
32
+  justify-content: center;
33
+  padding: 20px;
34
+}
35
+
36
+.main__container {
37
+  width: 768px;
38
+}
39
+
40
+/* sidebar */
41
+.sidebar {
42
+  background: #496893;
43
+  color: #ffffff;
44
+  min-height: 100vh;
45
+  padding: 20px 0;
46
+  width: 150px;
47
+}
48
+
49
+.sidebar__title {
50
+  color: #ffffff;
51
+  font-size: 24px;
52
+}
53
+
54
+.sidebar__title,
55
+.nav__item {
56
+  padding: 5px 10px;
57
+}
58
+
59
+.nav__item:hover {
60
+  background: #ffffff;
61
+}
62
+
63
+.nav__item:hover a {
64
+  color: #496893;
65
+}
66
+
67
+.nav__link {
68
+  color: white;
69
+}
70
+
71
+.nav__link:hover {
72
+  text-decoration: underline;
73
+}
74
+
75
+/* forms */
76
+
77
+.form__field {
78
+  display: flex;
79
+  flex-direction: column;
80
+  margin: 5px 0;
81
+  width: 100%;
82
+}
83
+
84
+.form__field,
85
+.form__label {
86
+  margin-bottom: 5px;
87
+}
88
+
89
+.form__date-field,
90
+.form__textarea,
91
+.form__text-field {
92
+  border: 1px solid #e8e8e8;
93
+  font-family: serif;
94
+  font-size: 16px;
95
+  padding: 5px;
96
+}
97
+
98
+.form__textarea {
99
+  resize: vertical;
100
+}
101
+
102
+.form__submit {
103
+  border: 1px solid #e8e8e8;
104
+  padding: 5px 10px;
105
+}
106
+
107
+/* post listing */
108
+.post-listing__item {
109
+  position: relative;
110
+}
111
+
112
+.post-listing__item--changed:before {
113
+  background-color: red;
114
+  border-radius: 50%;
115
+  content: '';
116
+  display: block;
117
+  height: 10px;
118
+  left: -15px;
119
+  position: absolute;
120
+  top: 3px;
121
+  width: 10px;
122
+}

+ 1
- 0
manifest.json View File

@@ -0,0 +1 @@
1
+{"assets":{"app_css.css":"app_css-a8e857a2075c5754ba39.css","app_css.js":"app_css.e509ac2debe5d5805fa0.js","app_js.js":"app_js.9dc1daad314671a279cc.js"},"publicPath":""}

+ 9179
- 0
package-lock.json
File diff suppressed because it is too large
View File


+ 25
- 0
package.json View File

@@ -0,0 +1,25 @@
1
+{
2
+  "name": "yird",
3
+  "version": "0.1.0",
4
+  "description": "Yird is for building websites.",
5
+  "main": "index.js",
6
+  "scripts": {
7
+    "build": "node_modules/.bin/webpack",
8
+    "watch": "node_modules/.bin/webpack --watch"
9
+  },
10
+  "author": "Dylan Baker <dylanbaker.ct@gmail.com>",
11
+  "license": "MIT",
12
+  "devDependencies": {
13
+    "@babel/core": "^7.2.2",
14
+    "@babel/preset-env": "^7.2.3",
15
+    "babel-loader": "^8.0.4",
16
+    "css-loader": "^2.1.0",
17
+    "manifest-revision-webpack-plugin": "^0.4.1",
18
+    "mini-css-extract-plugin": "^0.5.0",
19
+    "node-sass": "^4.11.0",
20
+    "sass-loader": "^7.1.0",
21
+    "style-loader": "^0.23.1",
22
+    "webpack": "^4.28.3",
23
+    "webpack-cli": "^3.1.2"
24
+  }
25
+}

+ 52
- 0
webpack.config.js View File

@@ -0,0 +1,52 @@
1
+const ManifestRevisionPlugin = require('manifest-revision-webpack-plugin')
2
+const MiniCssExtractPlugin = require('mini-css-extract-plugin')
3
+
4
+const path = require('path')
5
+
6
+module.exports = {
7
+  mode: 'production',
8
+  entry: {
9
+    app_js: ['./assets/js/index.js'],
10
+    app_css: ['./assets/scss/style.scss'],
11
+  },
12
+  output: {
13
+    path: '/Users/dylan/src/yird/yird/static',
14
+    filename: '[name].[chunkhash].js',
15
+    chunkFilename: '[id].[chunkhash].js',
16
+  },
17
+  resolve: {
18
+    extensions: ['.js', '.css', '.scss'],
19
+  },
20
+  module: {
21
+    rules: [
22
+      {
23
+        test: /\.js$/,
24
+        exclude: /node_modules/,
25
+        use: {
26
+          loader: 'babel-loader',
27
+          options: {
28
+            presets: ['@babel/preset-env']
29
+          }
30
+        }
31
+      },
32
+      {
33
+        test: /\.s?css/,
34
+        use: [
35
+          MiniCssExtractPlugin.loader,
36
+          { loader: 'css-loader' },
37
+          { loader: 'sass-loader' },
38
+        ],
39
+      },
40
+    ],
41
+  },
42
+  plugins: [
43
+    new ManifestRevisionPlugin('manifest.json', {
44
+      rootAssetPath: './assets',
45
+      ignorePaths: ['/styles', '/scripts'],
46
+    }),
47
+    new MiniCssExtractPlugin({
48
+      filename: '[name]-[contenthash].css'
49
+    }),
50
+
51
+  ],
52
+}

+ 13
- 1
yird/app.py View File

@@ -1,10 +1,22 @@
1 1
 from flask import Flask, redirect, render_template, request, url_for
2 2
 
3
+from flask_webpack import Webpack
4
+
3 5
 from yird.services.posts import PostsService
4 6
 
5 7
 from yird.settings import Settings
6 8
 
7 9
 app = Flask(__name__)
10
+
11
+params = {
12
+    'DEBUG': True,
13
+    'WEBPACK_MANIFEST_PATH': '../manifest.json'
14
+}
15
+app.config.update(params)
16
+
17
+webpack = Webpack()
18
+webpack.init_app(app)
19
+
8 20
 yird_settings = Settings()
9 21
 
10 22
 
@@ -45,4 +57,4 @@ def generate():
45 57
     return redirect(url_for('index'))
46 58
 
47 59
 if __name__ == "__main__":
48
-    app.run(debug=True)
60
+    app.run()

+ 0
- 0
yird/static/.gitkeep View File


+ 0
- 122
yird/static/css/style.css View File

@@ -1,122 +0,0 @@
1
-/* global */
2
-
3
-* {
4
-	box-sizing: border-box;
5
-	margin: 0;
6
-	padding: 0;
7
-}
8
-
9
-ul {
10
-	list-style: none;
11
-}
12
-
13
-a {
14
-	text-decoration: none;
15
-}
16
-
17
-.heading {
18
-	border-bottom: 1px solid #000000;
19
-	font-size: 24px;
20
-	margin-bottom: 15px;
21
-}
22
-
23
-/* layout */
24
-
25
-.container {
26
-  display: flex;
27
-}
28
-
29
-.main {
30
-	display: flex;
31
-	flex: 1;
32
-	justify-content: center;
33
-	padding: 20px;
34
-}
35
-
36
-.main__container {
37
-	width: 768px;
38
-}
39
-
40
-/* sidebar */
41
-.sidebar {
42
-  background: #496893;
43
-	color: #ffffff;
44
-	min-height: 100vh;
45
-	padding: 20px 0;
46
-	width: 150px;
47
-}
48
-
49
-.sidebar__title {
50
-	color: #ffffff;
51
-	font-size: 24px;
52
-}
53
-
54
-.sidebar__title,
55
-.nav__item {
56
-	padding: 5px 10px;
57
-}
58
-
59
-.nav__item:hover {
60
-	background: #ffffff;
61
-}
62
-
63
-.nav__item:hover a {
64
-	color: #496893;
65
-}
66
-
67
-.nav__link {
68
-	color: white;
69
-}
70
-
71
-.nav__link:hover {
72
-	text-decoration: underline;
73
-}
74
-
75
-/* forms */
76
-
77
-.form__field {
78
-	display: flex;
79
-	flex-direction: column;
80
-	margin: 5px 0;
81
-	width: 100%;
82
-}
83
-
84
-.form__field,
85
-.form__label {
86
-	margin-bottom: 5px;
87
-}
88
-
89
-.form__date-field,
90
-.form__textarea,
91
-.form__text-field {
92
-	border: 1px solid #e8e8e8;
93
-	font-family: serif;
94
-	font-size: 16px;
95
-	padding: 5px;
96
-}
97
-
98
-.form__textarea {
99
-	resize: vertical;
100
-}
101
-
102
-.form__submit {
103
-	border: 1px solid #e8e8e8;
104
-	padding: 5px 10px;
105
-}
106
-
107
-/* post listing */
108
-.post-listing__item {
109
-	position: relative;
110
-}
111
-
112
-.post-listing__item--changed:before {
113
-	background-color: red;
114
-	border-radius: 50%;
115
-	content: '';
116
-	display: block;
117
-	height: 10px;
118
-	left: -15px;
119
-	position: absolute;
120
-	top: 3px;
121
-	width: 10px;
122
-}

+ 0
- 8
yird/static/js/index.js View File

@@ -1,8 +0,0 @@
1
-// document.querySelector('[data-generate-button]').addEventListener('click',
2
-//   function (e) {
3
-//     var r = confirm('Are you sure? This will overwrite any existing content.');
4
-//     if (!r) {
5
-//       e.preventDefault();
6
-//     }
7
-//   }
8
-// );

+ 2
- 2
yird/templates/layout.html.j2 View File

@@ -3,7 +3,7 @@
3 3
 <head>
4 4
   <meta charset="UTF-8">
5 5
   <meta name="viewport" content="width=device-width">
6
-  <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static', filename='css/style.css') }}">
6
+  <link rel="stylesheet" href="{{ url_for('static', filename=asset_url_for('app_css.css')) }}">
7 7
   <title>My Website</title>
8 8
 </head>
9 9
 <body>
@@ -34,6 +34,6 @@
34 34
       </div>
35 35
     </main>
36 36
   </div>
37
-  <script src="{{ url_for('static', filename='js/index.js') }}"></script>
37
+  <script src="{{ url_for('static', filename=asset_url_for('app_js.js')) }}"></script>
38 38
 </body>
39 39
 </html>

Loading…
Cancel
Save