Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transform function #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jahredhope
Copy link
Collaborator

This change is an attempt to address the below issue. Depending on any feedback on this issue this change may not be needed.

closes: #121

Transform function

Adds a transform function that allows locals to be transformed into the variables expected by render function.
Transform function runs per render path.

Example usage:

const entries
new StaticSiteGeneratorPlugin({
  transformLocals: (locals) => {
  const mainChunkAssets = locals.webpackStats.assetsByChunkName.main
    .map(value => `${publicPath}${value}`);

  const clientJsEntries = mainChunkAssets
    .filter(value => value.match(/\.js/))

  const clientCssEntries = mainChunkAssets
    .filter(value => value.match(/\.css$/))

    return { ...locals, clientJsEntries, clientCssEntries}
  }
})

@coveralls
Copy link

coveralls commented Mar 5, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 79eb95c on jahredhope:add-mapping-function into ee7b961 on markdalgleish:master.

@jahredhope
Copy link
Collaborator Author

Unable to get tests to pass.
Attempted completely fresh install, passed locally but CI fails.

This change now limits tests to comparing HTML files. But would appreciate advice how to fix differences between CI and local.

@jahredhope jahredhope force-pushed the add-mapping-function branch 2 times, most recently from 9a79376 to 81d44ec Compare March 21, 2018 09:33
@jahredhope
Copy link
Collaborator Author

After further discussion it seems it may be cleaner to deprecate locals as a object and for the user to use the previously described transformLocals behaviour for any use of custom values.
This change now represents this behaviour.

README.md Outdated

plugins: [
new StaticSiteGeneratorPlugin({
locals: ({ path }) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth adding webpackStats to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request: Add support for a 'render-time' method to manipulate locals
5 participants