
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@mish.dev/vite-convert-pug-in-html
Advanced tools
A Vite plugin to seamlessly integrate Pug for multi-page applications, on-the-fly development server compilation, and component templating.
A Vite plugin for a seamless, zero-config Pug integration in multi-page applications (MPA).
This plugin automatically detects your .pug
pages, compiles them on-the-fly in the dev server with support for "pretty URLs" (e.g., /about
), and builds them into a clean, nested directory structure for production.
.pug
files in your source directory to create a multi-page application without manual configuration./about
or /contact
) and serves the correctly compiled Pug file on-the-fly..pug
file (including partials via include
or extends
) is changed.resolve.alias
config directly in Pug include
or extends
statements.locals
option.<script src="/main.ts">
) in Pug, and Vite will bundle and inject them correctly.pugOptions
.npm install @mish.dev/vite-convert-pug-in-html -D
The plugin requires pug
to be installed in your project:
npm install pug -D
Add the plugin to your vite.config.ts
. For most projects, no options are required.
The plugin automatically scans your project's root
directory (by default, src
if you've set root: 'src'
) for .pug
files to build your application.
_
(e.g., _layout.pug
), treating them as partials.src/index.pug
becomes the site's root (/
).src/pages/about.pug
becomes accessible at /about
.src/pages/contact/index.pug
becomes accessible at /contact
.Recommended Project Structure:
.
├── src/
│ ├── components/
│ │ └── _header.pug
│ ├── pages/
│ │ ├── about.pug
│ │ └── contact/
│ │ └── index.pug
│ ├── templates/
│ │ └── _layout.pug
│ ├── index.pug
│ └── main.ts
└── vite.config.ts
vite.config.ts:
import { defineConfig } from 'vite';
import { viteConvertPugInHtml } from '@mish.dev/vite-convert-pug-in-html';
export default defineConfig({
// Tell Vite that your source code is in the 'src' directory
root: 'src',
plugins: [
// That's it! No options needed for a standard setup.
viteConvertPugInHtml(),
],
build: {
// Make sure Vite builds to the project root, not inside 'src'
outDir: '../dist',
},
});
When you run vite build
, the plugin automatically generates:
dist/index.html
(from src/index.pug
)dist/about/index.html
(from src/pages/about.pug
)dist/contact/index.html
(from src/pages/contact/index.pug
)In the dev server, you can access these pages at /
, /about
, and /contact
.
Forget manual replacements. Just link your TypeScript/JavaScript entry point directly in your main layout file. Vite will handle the rest.
src/templates/_layout.pug:
doctype html
html
head
title My Awesome Site
// Vite will automatically inject the compiled CSS here
body
block content
// Just point to your TS/JS entry file.
// Vite will bundle it and add the correct hashed path on build.
script(src="/main.ts" type="module")
locals
Use the locals
option to make data available in all your Pug templates. This is the perfect place for site-wide constants, helper functions, or environment variables.
vite.config.ts:
import { defineConfig } from 'vite';
import { viteConvertPugInHtml } from '@mish.dev/vite-convert-pug-in-html';
export default defineConfig({
root: 'src',
plugins: [
viteConvertPugInHtml({
locals: {
SITE_NAME: 'My Awesome Company',
PHONE: '+1 (800) 555-1234',
CURRENT_YEAR: new Date().getFullYear(),
},
}),
],
build: {
outDir: '../dist',
},
});
src/templates/_layout.pug:
doctype html
html
head
//- Variables from `locals` are globally available
title= SITE_NAME
body
block content
footer
p © #{CURRENT_YEAR} #{SITE_NAME}
p Call us at: #{PHONE}
The plugin automatically uses aliases from your resolve.alias
config, making includes clean and maintainable.
vite.config.ts:
import { defineConfig } from 'vite';
import { viteConvertPugInHtml } from '@mish.dev/vite-convert-pug-in-html';
import { resolve } from 'path';
export default defineConfig({
root: 'src',
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
plugins: [viteConvertPugInHtml()],
build: {
outDir: '../dist',
},
});
src/pages/about.pug:
extends @/templates/_layout.pug
block content
//- Use the '@' alias to include a component
include @/components/_header.pug
h1 About Us
pugOptions
PugOptions
(from pug
){}
An object of options passed directly to pug.render()
. Use this for advanced Pug features like filters or custom doctypes.
viteConvertPugInHtml({
pugOptions: {
pretty: true, // Make the output HTML readable (default)
},
}),
locals
Record<string, any>
{}
An object of global variables that will be available in all your Pug templates. This is merged with pugOptions
before rendering.
FAQs
A Vite plugin to seamlessly integrate Pug for multi-page applications, on-the-fly development server compilation, and component templating.
We found that @mish.dev/vite-convert-pug-in-html demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.