3.2.0 • Published 3 months ago

@hoast/process-javascript v3.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
3 months ago

@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.