npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

templatifier-webpack-plugin

v1.0.12

Published

A Webpack plugin for transforming HTML templates with custom tags.

Downloads

3

Readme

Templatifier-Webpack-Plugin

📊📈📉 Templatifier Webpack Plugin

License LinkedIn Watch on GitHub Star on GitHub Tweet

Webpack Plugin to Transform Normal HTML Files into Django HTML Templates

templatifier-webpack-plugin allows you to seamlessly integrate the transformation of normal HTML files into Django HTML templates as part of the Webpack build process. This helps maintain a streamlined workflow between frontend development and Django template integration.

TemplatifierWebpackPlugin is a custom Webpack plugin designed to transform your HTML templates by replacing specific comment markers with Django template tags. This plugin is particularly useful if you're working with Django templates and static files, allowing you to automate the injection of {% load static %}, {% csrf_token %}, and static file routes into your HTML files.

Installation

You can install this plugin via npm:

npm install templatifier-webpack-plugin --save-dev

Usage

Basic Configuration

To use the TemplatifierWebpackPlugin, add it to the plugins section of your Webpack configuration file. You can specify the inputFile option to point to the HTML file you want to process and the outputDirectory option to specify where the transformed file should be saved.

Here’s an example configuration:


const TemplatifierWebpackPlugin = require('templatifier-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    // Your other Webpack configuration settings
    plugins: [
        new TemplatifierWebpackPlugin({
            inputFile: './src/html/index.html',
            outputDirectory: 'prod'
        }),
        new TemplatifierWebpackPlugin({
            inputFile: './src/html/login.html',
            outputDirectory: 'prod'
        }),
        new TemplatifierWebpackPlugin({
            inputFile: './src/html/register.html',
            outputDirectory: 'prod'
        }),
        new TemplatifierWebpackPlugin({
            inputFile: './src/html/reset_password.html',
            outputDirectory: 'prod'
        }),
        new TemplatifierWebpackPlugin({
            inputFile: './src/html/reset_password_confirm.html',
            outputDirectory: 'prod'
        }),
          
        new HtmlWebpackPlugin({
            template: './src/html/prod/index.html',
            filename: 'html/index.html',
            chunks: ['index'],
            inject: false,
        }),
    ]
};

Options

  • inputFile: (string) The path to the input HTML file that should be processed. Default: 'src/template.html'.
  • outputDirectory: (string) The directory where the transformed HTML file will be saved. This path is relative to the directory containing the inputFile. Default: 'templatifier'.
  • writeOriginal: (boolean|string) If set to true, the plugin will overwrite the original input file with the transformed HTML. Default: false.

HTML Template Directives

The plugin processes the following custom comment markers in your HTML:

Load Static:

<!-- <cb-templatifier type="loadstatic" /> -->

This will inject {% load static %} at the top of your HTML file.

Static CSS:

<!-- <cb-templatifier type="static-css" route="path/to/your/style.css" /> -->

This will replace the comment with:

<link href="{% static 'path/to/your/style.css' %}" rel="stylesheet">

Static Script:

<!-- <cb-templatifier type="static-script" route="path/to/your/script.js" /> -->

This will replace the comment with:

<script defer="defer" src="{% static 'path/to/your/script.js' %}"></script>

CSRF Token:

<!-- <cb-templatifier type="csrf_token" /> -->

This will replace the comment with:

{% csrf_token %}

Example Usage Scenario

If you're working on a Django project and need to ensure that all your HTML files in the src/html/ directory have the appropriate Django template tags, you can use TemplatifierWebpackPlugin to automate this process.

Consider the following file structure:

├── src
│   ├── html
│   │   ├── index.html
│   │   ├── login.html
│   │   ├── register.html
│   │   ├── reset_password.html
│   │   └── reset_password_confirm.html

You can configure multiple instances of the TemplatifierWebpackPlugin to process each file individually, and the processed files will be saved in the prod/ directory within src/html/.

License

This plugin is licensed under the MIT License. See the LICENSE file for details.

Contributing

Feel free to contribute by submitting issues or pull requests to the repository. Contributions are welcome!

Support

For any issues or questions, please open an issue on the GitHub repository.

About

We are www.cubode.com an startup focussed on No Code, AI and OpenSouce.

Templatifier-webpack-plugin has been developed with 💙 for the community, check Templatifier (https://www.npmjs.com/package/templatifier & https://github.com/cubode/templatifier)