https://github.com/lcneves/pug-module
Compiles pug files into a module that can be required.
https://github.com/lcneves/pug-module
browserify module nodejs pug pug-template-engine require webpack
Last synced: 2 months ago
JSON representation
Compiles pug files into a module that can be required.
- Host: GitHub
- URL: https://github.com/lcneves/pug-module
- Owner: lcneves
- Created: 2017-05-10T05:18:26.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-07-25T20:02:36.000Z (almost 8 years ago)
- Last Synced: 2025-10-14T02:14:08.772Z (9 months ago)
- Topics: browserify, module, nodejs, pug, pug-template-engine, require, webpack
- Language: JavaScript
- Homepage:
- Size: 1.42 MB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pug-module
Compiles multiple .pug files into a module that can be used in Node, Browserify or Webpack apps with `require`.
## Getting started
```
$ npm install pug-module --save-dev
$ npm install pug-runtime --save
```
package.json:
```
"scripts": {
"build:pug": "pug-module views/*.pug -o lib/templates.js",
// [...]
```
Back to the console:
```
npm run build:pug
```
Your app:
```
const templates = require('lib/templates.js');
console.log(templates.helloWorld());
//
Hello world!
console.log(templates.helloParameter({ parameter: 'Pug' });
//
Hello Pug!
```
## Usage
```
node_modules/.bin/pug-module [options] path/to/files*.pug -o path/to/compiled.js
```
### Options
`-q, --quiet`: Do not output success message to console.
`-r, --recursive`: Find all pug files under the specified directories
and generate camelcase name from the relative directory/file path.
Given mydir as a parameter and mydir/foo/bar/helloWorld.pug, the module name will resolve to fooBarHelloWorld(...).
A directory structure like this:
```
mail
--welcome
----subject.pug
----html.pug
--confirm
----subject.pug
----html.pug
```
will generate the modules
`welcomeSubject`, `welcomeHtml`, `confirmSubject`, and `confirmHtml`.
### How is the template function name composed?
The `pug-module` tool will read each `.pug` filename, strip the extension, convert it to camelCase and strip all non-alphanumeric characters.
```
views/some_cool-template+2.pug
// compiles to
module.exports['someCoolTemplate2'] = function (...)
```