posthtml / posthtml-modules

Modules Plugin
MIT License
84 stars 11 forks source link

feat: pass locals as option #57

Closed cossssmin closed 3 years ago

cossssmin commented 3 years ago

This PR adds support for passing locals inside the options object, as described in #56

Besides the locals='' attribute, we can now also pass data to a module through a locals object in the plugin options:

posthtml()
  .use(require('posthtml-modules')({
    locals: {} // custom data object
   }))
  .process(readFileSync('index.html', 'utf8'))
  .then(result => result)
})

Note: lodash was added as a dependency so that we can safely deep merge the locals from options with the ones from the locals="" attribute. Uses destructuring, so we don't load the entire library unnecessarily.

If merged, closes #56

Scrum commented 3 years ago

@cossssmin publish v0.7.0