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

cameronjs-html-webpack-plugin

v0.5.1

Published

Adds syntax for simple HTML layouts and partials

Downloads

22

Readme

CameronJS HTML Webpack Plugin

Adds support for simple HTML layouts and partials

Install

yarn add cameronjs-html-webpack-plugin

Add to your webpack.config.js:

const CameronJSHtmlWebpackPlugin = require("cameronjs-html-webpack-plugin");

module.exports = {
  // ...
  output: {
    //...
    path: path.resolve(__dirname, "public")
  },
  plugins: [
    new CameronJSHtmlWebpackPlugin({
      source: "./src/html",
      layouts: "layouts"
    })
  ],
  // ...
};

Options

source is relative to webpack.config.js and is where your HTML templates live.

layouts is relative to source and is where your layout files live.

Generated HTML pages will be emitted to the output.path set in the config file.

Usage

Layouts

Layouts surround your HTML content and provide a "frame". The standard declarations for your pages probably don't change much between pages so they're perfect for a layout:

<!-- src/html/layouts/application.html -->

<!DOCTYPE html>
<html>
<head>
  <title>@@title</title>
</head>
<body>
  @@content
</body>
</html>

You use @@content to denote where the real content of your page will be inserted into the layout and any other variables you want to be replaced by prefixing them with @@.

To denote that a page should use a layout add a @@layout declaration at the top of the page to say which one to use, with an optional list of those variables you want to substitute:

<!-- src/html/index.html -->

@@layout("application", { "title": "My Site" })
<h1>Hello, world</h1>

The final rendered HTML will be emitted to wherever output.path is set in webpack.config.js:

<!-- public/index.html -->

<!DOCTYPE html>
<html>
<head>
  <title>My Site</title>
</head>
<body>
  <h1>Hello, world</h1>
</body>
</html>

Layouts are great for parts of your site that don't change between pages. This way you write them once and share them everywhere.

Partials

Partials are smaller snippets of HTML that you want to share between pages. A navigation bar is a good example:

<!-- src/html/_nav.html -->

<nav>
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/account">Account</a></li>
  </ul>
</nav>

Note that the filename must begin with a _underscore. This helps you distinguish between full pages and partials when you're looking at a list of files in your editor. In the page where you want to use the partial you'll provide a @@partial declaration (this time without the leading underscore):

<!-- src/html/index.html -->

@@partial("nav.html")
<h1>Hello, world</h1>

And the final built HTML page would look like:

<!-- public/index.html -->

<nav>
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/account">Account</a></li>
  </ul>
</nav>

<h1>Hello, world</h1>

(Note the @@layout declaration was not present so this page won't be wrapped in a layout.)

You can pass variable substitutions to partials if you want the parent page to make some data available to the child partial.

<!-- src/html/parts/_title.html -->

<header>
  <h1>@@pageTitle</h1>
  <h2>Welcome @@user.name</h2>
</nav>

<!-- src/html/index.html -->

@@partial("parts/title.html", { "pageTitle": "Welcome!", "user": { "name": "Rob" } })

<main>
  <p>Lorem ipsum dolar sit amet...</p>
</main>

Note that in the above example the partial lived in a different directory than the main file.

Notes

You can combine partials and layouts and reference one from the other. Perhaps you have multiple layouts but they should all share the same <head> tag content. Include the @@partial in both layouts and you're good to go:

<!-- src/html/layouts/site.html -->

<!DOCTYPE html>
<html>
@@partial("head.html")
<body>
  <h1>My Site</h1>
  @@content
</body>
</html>

<!-- src/html/layouts/admin.html -->

<!DOCTYPE html>
<html>
@@partial("admin.html")
<body>
  <h1>Admins Only</h1>
  @@content
</body>
</html>

Thanks

This package was made possible by digging through the source on file-include-webpack-plugin and this plugin borrowed some code from it!