esbuild plugin to work with pug (jade) files.
- Compiles
.pugand.jadefiles - Supports various configuration file formats
- Integrates with esbuild seamlessly
npm install --save-dev esbuild-pugimport { build } from 'esbuild';
import { pugPlugin } from 'esbuild-pug';
build({
entryPoints: [ 'app.js' ],
bundle: true,
outfile: 'out.js',
plugins: [ pugPlugin() ],
})
.catch(() => process.exit(1));You can configure the plugin by passing options:
pugPlugin({
basedir: './src/',
// other pug options
})You can configure your project to pass the additional options.
The plugin accepts all standard Pug options, plus:
root: Set the root directory for resolving includes and extends.loader: Choose betweentext(default) orjsoutput.
You can see the supported options here.
esbuild-pug supports configuration files in several formats:
- JavaScript - use
.pugrc.jsorpug.config.jsand export an object containing your configuration. - YAML - use
.pugrc, .pugrc.yamlor.pugrc.ymlto define the configuration structure. - JSON - use
.pugrc.jsonto define the configuration structure. - package.json - create an
pugConfigproperty in yourpackage.jsonfile and define your configuration there.
If there are multiple configuration files in the same directory, esbuild-pug will only use one. The priority order is as follows:
package.json.pugrc.pugrc.json.pugrc.yaml.pugrc.yml.pugrc.js.pugrc.cjspug.config.jspug.config.cjs
Here's an example configuration file that sets Pug basedir option (again, see whole list of supported options here):
-
.pugrc.json(JSON){ "basedir": "./src/" } -
.pugrc(YAML)basedir: ./src/
-
pug.config.js(JavaScript)module.exports = { basedir: './src/' };
P.S.: Either of that should work. No need to create all of them. See Configuration File Formats.
Run npm run build to build the project. The build artifacts will be stored in the dist/ directory.
Contributions are welcome! Please feel free to submit a Pull Request.