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

@scandipwa/scandipwa-template-plugin-system

v0.1.23

Published

This package provides the template plugin system used by [Create Scandipwa App](https://github.com/scandipwa/create-scandipwa-app).

Downloads

3,913

Readme

@scandipwa/scandipwa-template-plugin-system

This package provides the template plugin system used by Create Scandipwa App.

Abstract

This template plugin system processes the template (the main markup file) file of the application.

It provides an opportunity to modify the template similarly to the process which is provided by CSA to modify the build configuration.

Use cases

  1. Your extension needs some additional HTML/PHP nodes in the template

  2. Your extension is incompatible with some existing HTML/PHP nodes in the template and needs to remove them

  3. Your extension needs to change attributes of the existing nodes to some other values

Limitations

  1. This tool is not meant for PHP code modifications. It offers an opportunity to interact with template as with text, but changing PHP or JS code such way would be considered a misuse, due to possible incompatibilities with a plugin written such a way. To change the PHP logic - change abstractions, not delta-modify the code.

Dependencies

xmldom is used to parse the markup to DOM and parse the DOM to markup. The DOM provided in the API is documented in this package's documentation.

lodash is used to process the initial template the same way as the loader of the HtmlWebpackPlugin does that.

How to use

  1. Define the paths to the template plugins in your package.json
{
    "scandipwa": {
        "build": {
            "templatePlugins": [
                "build-config/template-modification"
            ]
        }
    },
}
  1. Use one of the provided APIs to modify the template

  2. See the modified template in the compiled version of your project

API reference

The processing happens during the build time. Don't let the API (which is really similar to what browsers have for DOM) trick you!

  1. overrideDOM({ dom, parser, serializer }): DOM

Interact with the DOM representation of the template. This is a recommended way to modify a template using this plugin system.

The DOM is parsed by the xmldom package, see its documentation for some precise information on the deeper API.

This API covers all of the regular needs: handling the DOM including additional interactions with PHP nodes.

A valid DOM should be returned from this method.

  1. overrideText({ markup }): string

Interact with the text representation of the template. It is not recommended to use this if you have an opportunity to use the first API.

This API is meant strictly for interaction with template types that are not supported by the first API, e.g. cshtml, Razor syntax etc.

Such plugins will be executed after the DOM plugins. A valid markup should be returned from this method.

Usage examples

  1. Adding an additional tag to the document
module.exports = {
    templatePlugin: {
        overrideDOM({ dom, parser, serializer }) {
            // Generate the node as you would do that in the browser scope
            const additionalLink = dom.createElement('link');
            additionalLink.setAttribute('rel', 'stylesheet');
            additionalLink.setAttribute('href', 'https://my-super-source/style.css');

            // Or parse it directly from the markup!
            const additionalLink = parser.parseFromString(
                `<link rel="stylesheet" href="https://my-super-source/style.css">`
            );

            // Modify the DOM that is going to be present in the application
            dom.getElementsByTagName('head')[0].appendChild(additionalLink);

            // Remember to always return DOM from this method!
            return dom;
        }
    }
};
  1. Adding additional non-supported by DOM syntax to the document
module.exports = {
    templatePlugin: {
        overrideText({ markup }) {
            const additionalText = `@{
                var greeting = "Welcome to our Razor-powered website!";
            }`;

            return additionalText.concat(markup);
        }
    }
};