@bam.tech/parcel-plugin-handlebars-mock
Advanced tools
Comparing version 2.0.0 to 2.0.1
{ | ||
"name": "@bam.tech/parcel-plugin-handlebars-mock", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Parcel plugin to populate html during development.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# @bam.tech/parcel-plugin-handlebars-mock | ||
Populate HTML file with mock data in development. | ||
It also let you register helper methods for handlebars | ||
@@ -11,2 +12,4 @@ ## Installation | ||
### Mock data | ||
- Create a `src/mock` directory. | ||
@@ -17,3 +20,3 @@ - For each html file (named `foo.html` for example), create a `src/mock/foo.html.js` with the mock content: | ||
module.exports = { | ||
bar: "baz", | ||
bar: 'baz', | ||
}; | ||
@@ -23,1 +26,13 @@ ``` | ||
- If `NODE_ENV` is `production`, then the plugin is not applied. | ||
### Register helper methods | ||
- create a `src/helper` directory with an `index.js` that register some templates | ||
```js | ||
const Handlebars = require('handlebars'); | ||
Handlebars.registerHelper('isArrayBig', (array) => { | ||
return array.length > 3; | ||
}); | ||
``` |
const handlebars = require('handlebars'); | ||
const HTMLAsset = require('parcel-bundler/src/assets/HTMLAsset'); | ||
const path = require('path') | ||
const path = require('path'); | ||
const MOCK_DIR = './src/mock'; | ||
const HELPER_DIR = './src/helper'; | ||
class HbsAsset extends HTMLAsset { | ||
parse(code) { | ||
require(path.join(__dirname, '../../../..', HELPER_DIR)); | ||
if (process.env.NODE_ENV === 'production') { | ||
return super.parse(code) | ||
return super.parse(code); | ||
} | ||
@@ -15,5 +18,5 @@ | ||
const mockData = require(path.join(__dirname, '../../../..', MOCK_DIR, this.basename)) | ||
const mockData = require(path.join(__dirname, '../../../..', MOCK_DIR, this.basename)); | ||
const html = template(mockData) | ||
const html = template(mockData); | ||
@@ -20,0 +23,0 @@ return super.parse(html); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1835
21
36
4