
Security News
New React Server Components Vulnerabilities: DoS and Source Code Exposure
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.
page-compiler
Advanced tools
This is a very simple, yet powerful and intuitive TypeScript framework and a collection of tools that makes web(app) development simple. PageCompiler does what you might expect: it compiles pages. With it, you can dynamically create static websites. PageC
This is a very simple, yet powerful and intuitive TypeScript framework and a collection of tools that makes web(app) development simple. PageCompiler does what you might expect: it compiles pages. With it, you can dynamically create static websites. PageCompiler's main purpose is performance: the compiled pages are supposed to be as fast as possible. You can expect near 100% Google Lighthouse scores on well formed pages, even with images. The most powerful feature of PageCompiler is the ability to interpolate JavaScript/TypeScript in your HTML files. This code will be executed at compile time. PageCompiler's built-in tools take advantage of this.
You can create an example project structure as follows:
$ npm i page-compiler
$ node node_modules/page-compiler/create-app --sass
This will create an empty page-compiler template app with SASS support. I would recommend installing a JS HTML template string extension like this one for VSCode for best development experience.
Open the compiler.ts file that has been created in the root directory.
You will see that the compilePages() function is called with an array of pages as its argument.
The HTML of a sample page can be placed here inside an html string.
You can obviously also put the html strings in a seperate files.
You don't have to write an entire HTML shell, as that would be very dull.
The PageShell tool does that for you.
The main SASS file for our page shell is located at src/sass/index.sass.
The main client-side TS file is located at src/js/index.ts.
You need to compile the TypeScript files before you can use import them into the compiler.
Simply keep a terminal window open and execute $ tsc.
The TypeScript Configuration file is already set up, so no need to worry about it.
You can import other JS, SASS and CSS files with the inline tools.
When your webapp is ready to be tested, compile the pages with $ node compiler.
The pages will be compiled into the root directory.
Use your favourite webserver and set the webroot to this directory to host your website.
This is the main reason I created PageCompiler. Images of all kinds (JPG, PNG, SVG, etc.) are a very important part of any modern website. But in plain HTML/CSS/JS, it is really hard to dynamically optimise the imagery on your website.
PageCompiler offers straightforward solutions to loading images into your webapps.
You can import JPGs, PNGs and other raster images with the importJPG() tool.
This tool compresses and converts the input images into different sizes and formats.
The importJPG() tool creates images in JPG and WEBP formats.
A <picture> HTML element is returned containing the source sets of the created images.
This tool takes care of all browser compatibility, so you can simply import an image with a single line of code.
You need to have imagemagick installed on your system in order to use this tool.
Example:
import { importJPG } from 'page-compiler'
/* html */ `
<div id="my-app">
${ importJPG('src/img/bear.png', { alt: 'An image of a bear' }) }
</div>
`
This code will get compiled into an HTML structure like this:
<div id="my-app">
<picture>
<source .../>
...
<img src="..."/>
</picture>
</div>
SVG images can be directly inlined within the HTML pages of your webapp. This reduces the request count and server load.
Example:
import { inlineSVG } from 'page-compiler'
/* html */ `
<div id="my-app">
${ inlineSVG('src/img/twitter-icon.svg', { classes: [ 'social-icon' ] }) }
</div>
`
This code will get compiled into an HTML structure like this:
<div id="my-app">
<svg class="social-icon">...</svg>
</div>
You can easily import fonts from Google Fonts with the importGoogleFont() tool.
Example:
import { importGoogleFont } from 'page-compiler'
const pageShell = new PageShell({
head: /* html */ `
${ await importGoogleFont('Roboto', [
{ weight: 300, italic: true },
{ weight: 500 }
]) }
`
})
You can use the font in CSS/SASS files:
.selector {
font-family: 'Roboto', sans-serif;
font-size: 500;
}
JS, CSS and SASS scripts can be directly inlined within the HTML pages of your webapp.
This reduces the request count and server load.
CSS and SASS scripts are auto-prefixed, and can be controlled by a .browserslistrc file.
Example:
import { inlineJS, inlineSASS, inlineExternalJS, inlineExternalCSS } from 'page-compiler'
/* html */ `
${ await inlineJS('src/js/contact-page.js') }
${ await inlineSASS('src/sass/contact-page.sass') }
${ await inlineExternalJS('https://some-cdn.com/some-contact-form-library.js') }
${ await inlineExternalCSS('https://some-cdn.com/some-contact-form-library.css') }
<div id="contact">
...
</div>
`
This code will get compiled into an HTML structure like this:
<script> ... </script>
<style> ... </style>
<script> ... </script>
<style> ... </style>
<div id="contact">
...
</div>
PageCompiler also has tools to make creating PWAs much easier. You can create a project structure for a PWA with SASS support with the following command:
$ node node_modules/page-compiler/create-app --sass --pwa
In the compiler.ts you will see the createPWAManifest() tool being used.
You can change and add fields of the manifest.
This command also creates a sample service worker file src/js/service-worker.js which handles caching.
It is imported using the importServiceWorker() tool in compiler.ts.
FAQs
This is a very simple, yet powerful and intuitive TypeScript framework and a collection of tools that makes web(app) development simple. PageCompiler does what you might expect: it compiles pages. With it, you can dynamically create static websites. PageC
The npm package page-compiler receives a total of 2 weekly downloads. As such, page-compiler popularity was classified as not popular.
We found that page-compiler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.