Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@webdiscus/pug-loader

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webdiscus/pug-loader - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

2

package.json
{
"name": "@webdiscus/pug-loader",
"version": "1.4.0",
"version": "1.4.1",
"description": "The pug loader resolves paths and webpack aliases in a pug template and compiles it to HTML or into a template function.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -17,2 +17,3 @@ [![npm version](https://badge.fury.io/js/@webdiscus%2Fpug-loader.svg)](https://badge.fury.io/js/@webdiscus%2Fpug-loader)

- up to 8x faster than original `pugjs/pug-loader` at webpack watching during compile changes in dependencies
- supports ES modules syntax in generated JS modules
- supports Webpack `resolve.alias`, work fine with and without the prefixes `~` or `@`, e.g. for the defined alias `Components` this works:

@@ -32,3 +33,3 @@ - `extends Components/layout.pug`

```js
const html = require('template.pug');
const tmpl = require('template.pug');
const html = tmpl({ key: "value" })

@@ -199,8 +200,12 @@ ```

### `pretty`
### `self`
Type: `boolean`<br>
Default: `false`<br>
This option is **deprecated** by pugjs and always is `false`. Don't use it.
Use the `self` as namespace for the local variables in template. It will speed up the compilation, but for access to variable, e.g. `myVariable`, you must write `self.myVariable`.
### `globals`
Type: `Array<string>`<br>
Default: `[]`<br>
Add a list of global names to make accessible in templates.
### `filters`

@@ -212,6 +217,7 @@ Type: `object`<br>

### `self`
Type: `boolean`<br>
Default: `false`<br>
Use the `self` as namespace for the local variables in template. It will speed up the compilation, but for access to variable, e.g. `myVariable`, you must write `self.myVariable`.
### `plugins`
Type: `Array<Object>`<br>
Default: `[]`<br>
Plugins allow to manipulate pug tags, template content in compile process.
How it works [see in source of pug](https://github.com/pugjs/pug/blob/master/packages/pug/lib/index.js).

@@ -223,12 +229,7 @@ ### `compileDebug`

### `globals`
Type: `Array<string>`<br>
Default: `[]`<br>
Add a list of global names to make accessible in templates.
### `pretty`
Type: `boolean`<br>
Default: `false`<br>
This option is **deprecated** by pugjs and always is `false`. Don't use it.
### `plugins`
Type: `Array<Object>`<br>
Default: `[]`<br>
Plugins allow to manipulate pug tags, template content in compile process.
How it works [see in source of pug](https://github.com/pugjs/pug/blob/master/packages/pug/lib/index.js).

@@ -235,0 +236,0 @@ ## Additional options of this implementation

@@ -69,10 +69,11 @@ const path = require('path'),

compileDebug: loaderOptions.debug || false,
globals: ['require', ...(loaderOptions.globals || [])],
// Load all requires as function. Must be true.
//globals: ['require', ...(loaderOptions.globals || [])],
globals: ['__asset_resource_require__', 'require', ...(loaderOptions.globals || [])],
// Include inline runtime functions must be true.
inlineRuntimeFunctions: true,
//inlineRuntimeFunctions: false,
// module must be false to get compiled function body w/o export code
module: false,
// default name of template function is `template`
name: loaderOptions.name || 'template',
name: 'template',
// the template without export module syntax, because the export will be determined depending on the method
module: false,
plugins: [resolvePlugin, ...(loaderOptions.plugins || [])],

@@ -101,5 +102,5 @@ };

const locals = loaderMethod.getLocals(merge(loaderOptions.data || {}, resourceParams)),
const locals = merge(loaderOptions.data || {}, resourceParams),
funcBody = Object.keys(locals).length ? injectExternalVariables(res.body, locals) : res.body,
output = loaderMethod.output(funcBody, options.name, locals, esModule);
output = loaderMethod.output(funcBody, locals, esModule);

@@ -106,0 +107,0 @@ callback(null, output);

@@ -5,8 +5,8 @@ /**

* @property {string} queryParam The same as `method`, but defined in resource query parameter.
* @property {function(string)} getLocals Get template variables. Here can be merged additional custom properties.
* @property {function(string)} require The inject require.
* @property {function(string, string, {}, boolean)} output Generates a output content.
* @property {function(string, {}, boolean)} output Generates a output content.
*/
const getExportCode = (esModule) => (esModule ? 'export default ' : 'module.exports=');
const requireAsset = (file) => `' + __asset_resource_require__('${file}') + '`;

@@ -23,5 +23,4 @@ /**

queryParam: 'pug-compile',
getLocals: (locals) => locals,
require: (file) => `require(${file})`,
output: (funcBody, name, locals, esModule) => funcBody + ';' + getExportCode(esModule) + name + ';',
output: (funcBody, locals, esModule) => funcBody + ';' + getExportCode(esModule) + 'template;',
},

@@ -32,9 +31,6 @@ {

queryParam: 'pug-render',
getLocals: (locals) => ({
...locals,
...{ __asset_resource_require__: (file) => `' + __asset_resource_require__(\`${file}\`) + '` },
}),
require: (file) => `locals.__asset_resource_require__(${file})`,
output: (funcBody, name, locals, esModule) =>
(getExportCode(esModule) + "'" + new Function('', funcBody + ';return ' + name + '')()(locals) + "';").replaceAll(
require: (file) => `requireAsset(${file})`,
output: (funcBody, locals, esModule) =>
getExportCode(esModule) +
("'" + new Function('requireAsset', funcBody + ';return template;')(requireAsset)(locals) + "';").replaceAll(
'__asset_resource_require__',

@@ -49,5 +45,4 @@ 'require'

queryParam: 'pug-rtrender',
getLocals: (locals) => locals,
require: (file) => `require(${file})`,
output: (funcBody, name, locals, esModule) => funcBody + ';' + getExportCode(esModule) + name + '();',
output: (funcBody, locals, esModule) => funcBody + ';' + getExportCode(esModule) + 'template();',
},

@@ -59,5 +54,4 @@ {

queryParam: null,
getLocals: (locals) => locals,
require: (file) => `(${file})`,
output: (funcBody, name, locals, esModule) => new Function('', funcBody + ';return ' + name + ';')()(locals),
output: (funcBody, locals, esModule) => new Function('', funcBody + ';return template;')()(locals),
},

@@ -64,0 +58,0 @@ ];

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc