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

webpack-tl-loader

v1.0.4

Published

nunjucks templating language pre-processor for your bundle

Downloads

7

Readme

webpack-tl-loader

( short for webpack-templating-language-loader )
Nunjucks templating language pre-processor for your bundle.

What it allows you to do

This loader runs nunjucks over your files before it gets written to the bundle. Nunjucks is a templating language very similar to Jinja2.

<div class="columns is-mobile is-multiline">
    {% for skill in skills %}
        {% for k, v in skill %}
            <div class="column is-6-mobile is-2-desktop is-4-tablet">
                <div class="card">
                    <div class="card-content">
                        <section class='mb-4'>
                            <h2>{{ k }}</h2>
                        </section>
                        <section>
                            <progress class="progress is-medium" value="{{ v }}" max="100">{{ v }}%</progress>
                        </section>
                    </div>
                </div>
            </div>
        {% endfor %}
    {% endfor %}
</div>

Directory structure requirements

This loader requires you to have a ./data folder within the root directory of your application. The reason why is explained further down in this README, but in short, it is for making data accessible to your templating context.

Data Context

Adding data to the template context

To be able to access static data in your templates, simply put .json files in the ./data folder.
Here is an example (./data/skills.json):

[
    {"python": 95 },
    {"javascript": 79 },
    {"C": 80},
    {"C++": 79},
    {"PHP": 89},
    {"Typescript": 79},
    {"Bash": 79},
    {"SQL": 60},
    {"CSS": 81},
    {"HTML": 90},
    {"SCSS": 82},
    {"Java": 60},
    {"React.js": 70},
    {"Vue.js": 50},
    {"Flask": 90},
    {"MongoDB": 69},
    {"Flutter": 40},
    {"React Native": 39},
    {"OpenGL": 60},
    {"Linux": 87},
    {"Kubernetes": 20},
    {"Elastic Search": 25},
    {"Firebase": 59},
    {"Wordpress": 86}
]

The loader will automatically make this data available in a global skills variable. It automatically names the variable exactly the same as the filename but without the .json extension.

Piping your data

You can also pipe your data through a function. I call this function modifier. Simply put a file in your ./data folder.
( ./data/modifier.js )
Here is an example:

const sortItems = (a, b) => {
    const akeys = Object.keys(a);
    const bkeys = Object.keys(b);
    
    const av = akeys ? a[akeys[0]] : 0;
    const bv = bkeys ? b[bkeys[0]] : 0;

    return bv - av;
}


module.exports = (data) => Object.assign(
    data,
    {
        "skills": data.skills.sort(sortItems),
    }
)

This example will sort the skills by their value.

Install

To install this loader, first run:

npm install -D webpack-tl-loader

And then edit your webpack config and add the following:

const config: webpack.Configuration = {

    ...

    module: {
        rules: [

            ...

            {
                test: /\.html$/,
                use: ["html-loader", "webpack-tl-loader"],
            },
        ]
    },
};

And now you are ready to start templating!