@hoast/process-javascript

3.2.0 • Public • Published

@hoast/process-javascript

Retrieve and execute JavaScript.

Install

npm install @hoast/process-javascript

Example

Input

File located at components/h1.js.

export default function({ contents }) {
  return '<h1>' . contents . '</h1>';
}

File located at pages/index.html.

Hello world!

Config

export default {
  collections: [{
    source: ['@hoast/source-readfiles', {
      directory: 'pages',
    }],
    processes: [
      ['@hoast/process-javascript', {
        importPath: 'components/h1.js',
      }],
      '@hoast/process-log',
    ],
  }],
}

Output

<h1>Hello world!</h1>

Options

  • {String} setProperty = 'contents' Dot notation path to the data property to which the result should be written.

  • {String} executeProperty = 'default' Dot notation of property on imported object to execute.

  • {String} importProperty = 'default' Dot notation of property path of script's file path.

  • {String} importPath = 'default' File path of the script to execute, if know file path on data is found.

  • {Array<String>} watchIgnore = [ '**/node_modules/**' ] Paths of files to ignore marking as dependencies when watching for changes.

  • {Function} filter = null Custom filter function. The item data is given as the parameter. Return true if it should be processed, return false if this processor should be skipped.

  • {Number} logLevel = 2 Log level given to the logger.

Package Sidebar

Install

npm i @hoast/process-javascript

Weekly Downloads

2

Version

3.2.0

License

MIT

Unpacked Size

9.97 kB

Total Files

6

Last publish

Collaborators

  • redkenrok