Skip to main content

Observes the assets directory for html files and copies them into the templates folder.

Project description

lektor-webpack-html-helper

This is a plugin for Lektor that adds support for generating templates with webpacks HtmlWebpackPlugin. These templates can be generated into Lektors assets folder which will be observed for newly created or modified html files. These files will then be copied over to Lektors templates folder so that they can be used by Lektor. This plugin depends on the lektor-webpack-support plugin to be really useful.

webpack/webpack.config.js

const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");


module.exports = {
    mode: "production",
    entry: {
        main: "./src/index.js"
    },
    output: {
        filename: "[name].bundle.js",
        path: path.dirname(__dirname) + "/assets/generated" 
    },
    optimization: {
        minimizer: [
            new HtmlWebpackPlugin({
                inject: false,
                filename: "layout_generated.html",
                template: "./src/layout_template.html"
            })
        ],
    },
    plugins: [
        new CleanWebpackPlugin(),
        new MiniCssExtractPlugin({
            filename: "[name].css"
        })
    ],
    module: {
        rules: [{
            test: /\.scss$/,
            use: [
                MiniCssExtractPlugin.loader,
                "css-loader",
                "sass-loader"
            ]
        }]
    }
}

webpack/src/layout_template.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{{ this.title }} &middot; {{ config.PROJECT.name }} </title>

    <% for (var css in htmlWebpackPlugin.files.css) { %>
    <link href="{{ '/generated/<%= htmlWebpackPlugin.files.css[css] %>' | asseturl }}" rel="stylesheet">
    <% } %>
</head>

<body>
    <main>
        {% block content %}
        {% endblock content %}
    </main>

    <% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
    <script src="{{ '/generated/<%= htmlWebpackPlugin.files.chunks[chunk].entry %>' | asseturl }}"></script>
    <% } %>
</body>

</html>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for lektor-webpack-html-helper, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size lektor_webpack_html_helper-0.1.3-py3-none-any.whl (3.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size lektor-webpack-html-helper-0.1.3.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page