-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3aeffaa
commit 923442d
Showing
8 changed files
with
93 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ venv/ | |
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
dist/ | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
import json | ||
|
||
import structlog | ||
|
||
from litestar.contrib.jinja import JinjaTemplateEngine | ||
from litestar.template.config import TemplateConfig | ||
from pathlib import Path | ||
|
||
from example_app.etc import app_resource | ||
log: structlog.BoundLogger = structlog.get_logger() | ||
|
||
|
||
def webpack_bundle(_, name: str): | ||
manifest_file = app_resource("static/bundles/manifest.json") | ||
webpack_bundles = json.load(open(manifest_file)) | ||
return webpack_bundles[name] | ||
def make_callback(static_dir: str): | ||
def webpack_bundle(_, name: str): | ||
manifest_file = Path(static_dir) / "js/manifest.json" | ||
webpack_bundles = json.load(open(manifest_file)) | ||
return webpack_bundles[name] | ||
|
||
def callback(engine: JinjaTemplateEngine) -> None: | ||
engine.register_template_callable( | ||
key="webpack_bundle", | ||
template_callable=webpack_bundle, | ||
) | ||
|
||
def register_template_callables(engine: JinjaTemplateEngine) -> None: | ||
engine.register_template_callable( | ||
key="webpack_bundle", | ||
template_callable=webpack_bundle, | ||
) | ||
return callback | ||
|
||
|
||
template_config = TemplateConfig( | ||
directory=Path(__file__).parent / "templates", | ||
engine=JinjaTemplateEngine, | ||
engine_callback=register_template_callables, | ||
) | ||
def create_template_config(template_dir: str, static_dir: str): | ||
return TemplateConfig( | ||
directory=template_dir, | ||
engine=JinjaTemplateEngine, | ||
engine_callback=make_callback(static_dir), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from litestar.status_codes import HTTP_200_OK | ||
from litestar.testing import TestClient | ||
from example_app.factory import AppConfig, create_app | ||
|
||
|
||
def test_index_page(): | ||
config = AppConfig(debug=True) | ||
app = create_app(config) | ||
with TestClient(app=app) as client: | ||
response = client.get("/") | ||
assert response.status_code == HTTP_200_OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
const path = require("path"); | ||
const webpack = require("webpack"); | ||
const BundleTracker = require("webpack-bundle-tracker"); | ||
const { WebpackManifestPlugin } = require('webpack-manifest-plugin'); | ||
const { WebpackManifestPlugin } = require("webpack-manifest-plugin"); | ||
|
||
module.exports = { | ||
context: __dirname, | ||
entry: { | ||
"main": "./static/js/index.js", | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, "example_app/static/bundles/"), | ||
filename: "[name]-[contenthash].js", | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: ['style-loader', 'css-loader'] | ||
}, | ||
{ | ||
test: /\.ttf$/, | ||
type: 'asset/resource' | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new BundleTracker({ path: __dirname, filename: "webpack-stats.json" }), | ||
new WebpackManifestPlugin({ | ||
publicPath: "static/bundles" | ||
}), | ||
context: __dirname, | ||
entry: { | ||
main: "./static/js/index.js", | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, "./dist/js"), | ||
filename: "[name]-[contenthash].js", | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: ["style-loader", "css-loader"], | ||
}, | ||
{ | ||
test: /\.ttf$/, | ||
type: "asset/resource", | ||
}, | ||
], | ||
}; | ||
}, | ||
plugins: [ | ||
new BundleTracker({ path: __dirname, filename: "webpack-stats.json" }), | ||
new WebpackManifestPlugin({ | ||
publicPath: "static/js", | ||
}), | ||
], | ||
}; |