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

prehtml-loader

v3.0.1

Published

Easily creates static HTML pages at build time using templates, components, interpolations, and/or preprocessings. No JS required and nothing new to learn ;)

Downloads

24

Readme

npm i -D prehtml-loader

Documentation is obsolete (2021/07/13), please wait new documentation

Websites using prehtml-loader:

  • https://github.com/denis-migdal/migdal.ovh
  • https://github.com/denis-migdal/keystroke.fr

See the directory /examples for some more advanced usage examples.

// ./src/main.js
module.exports = {

	pages_input_dir: './src/', // optionnal
	pages_output_dir: './dist/pages/', // optionnal
	pages: {
		home: { __src: 'home', __args: { name: 'Denis Migdal' } },
		error_404: { __src: 'error', __args: { code: 404 } },
		error_403: { __src: 'error', __args: { code: 403 } },
		demos: { // this is a directory
			demo_1: {__src: 'demos/demo_1'},
			demo_2: {__src: 'demos/demo_2'}
		}
	}

};

Tip: You can even dynamically generate your website structure from your project.

// ./webpack.config.js
let website = require('./src/main.js');

let {build_website} = require('prehtml-loader/webpack_helper.js');

let html_config = (dst_path, src) => { // write here how you want HTML files to be build.

	return {
		module: {
			rules: [{
				enforce: 'post',
				test: /\.html$/,
				use: {
					loader: 'file-loader',
					options: {
						outputPath: './../', // required
						name: dst_path
					}
				}
			},{
				test: /\.html$/,
				use: ['prehtml-loader'],
			}
		]},
		entry: { 
			main: src
		},
		output: {
			path: path.resolve(__dirname, 'out'),
			publicPath: '',
			filename: `${dst_path}.junk`,
			//clean: true
		}
	};
};

let js_config = (dst_path, src) => {  // write here how you want JS files to be build.

	return {
		module: {},
		entry: {
			main: src
		},
		output: {
			path: path.resolve(__dirname),
			publicPath: '',
			filename: dst_path,
			//clean: true
		}
	};
};

module.exports = build_website(website, html_config, js_config);
// ./src/error/index.html
You got an error !

Error {{code}} // contents inside {{}} are evaluated.

{{let message = ''; if(error == 403) message = 'Forbidden !'; message}} // prints 'Forbidden !' if the code is 403.

<div class='message'></div>
// ./src/component/index.html
<div>Hello ! I am {{name}}</div>
// ./src/home/index.html
<component template='../component' name='{{name}}'></component> // use '' to surround the value.
<html>
	<head>
		<title>{{title}}</title>
	</head>
	<header>My header</header>
	<component template='{{page}}' __args='{{args}}'></component> // includes the page content
	// __args enables to set all arguments at once.
	// {{__args}} can also be used, it contains all arguments given to the page.
	<footer>My footer</footer>
</html>
// ./src/main.js
module.exports = {

	templates_input_dir: `${__dirname}/`, // __dirname required
	templates: {
		__default:{ // the default template
			__src: 'template',
			__args: {
				title: 'Error'
			}
		},
		template2:{ // another template (optionnal)
			__src: 'template',
			__args: {
				title: 'Home'
			}
		}
	},

	pages_input_dir: './src/', // optionnal
	pages_output_dir: './dist/pages/', // optionnal
	pages: {
		home: { __src: 'home', __args: { name: 'Denis Migdal' }, __template: 'template2' }, // use the template2 for this page.
		error_404: { __src: 'error', __args: { code: 404 } }, // use the default template
		error_403: { __src: 'error', __args: { code: 403 }, __template_args: {title: 'Error 403'} }, // use the default template and override its arguments
		demos: { // this is a directory
			demo_1: {__src: 'demos/demo_1', _template: 'none'}, // don't use a template for this page
			demo_2: {__src: 'demos/demo_2', __template: 'none',} // don't use a template for this page
		}
	}

};

Just put a JS file named as the html file you which to preprocess.

// ./src/error/index.html.js

module.exports = {

	prerender: function($, options) { // use it to modify the current html file before the components has been included.

		let message = '';
		if( options.code == 404 )
			message = 'not found';

		$('.message').text( message ); // JQuery interface.
	}

	render: function($, options) { // use it to modify the current html file after the components has been included.
		// ...
	}
};
rules: [{
	enforce: 'post',
	test: /\.html$/,
	use: {
		loader: 'file-loader',
		options: {
			outputPath: './../', // required
			name: dst_path
		}
	}
},{
	test: /\.html$/,
	// put your html-loader configuration here.
	// note: you may need to use extract-loader after html-loader.
},{
	test: /\.html$/,
	use: ['prehtml-loader'],
}]