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

Support per-page HTML template customisation via 'mains' #1029

Merged
merged 2 commits into from Aug 21, 2018
Merged

Support per-page HTML template customisation via 'mains' #1029

merged 2 commits into from Aug 21, 2018

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Aug 21, 2018

This adds support for defining each entry point in mains as an object, where the path to the entry point is now defined under an entry property, and any other properties can be used by presets for page-specific options. (The short form using a string is still supported.)

In the case of @neutrinojs/web (and presets that inherit from it), these additional properties are then used to override the options passed to html-webpack-plugin, allowing for page-specific customisation of the generated HTML template.

For example:

module.exports = {
  options: {
    mains: {
      index: {
        entry: './index',
        // Options here take priority over the preset's `html` options below.
        title: 'Site Homepage',
      },
      admin: {
        entry: './admin',
        title: 'Admin Dashboard',
      },
      account: {
        entry: './user',
        inject: true,
        template: './my-custom-template.html',
      },
    }
  },
  use: ['@neutrinojs/web', {
    // Customise the defaults used for all pages.
    html: {
      minify: false,
    }
  }]
}

For a list of the available html-webpack-plugin options, see:
https://github.com/jantimon/html-webpack-plugin#options

Fixes #865.

This adds support for defining each entry point in `mains` as an
object, where the path to the entry point is now defined under an
`entry` property, and any other properties can be used by presets
for page-specific options. (The short form using a string is still
supported.)

In the case of `@neutrinojs/web` (and presets that inherit from it),
these additional properties are then used to override the options
passed to `html-webpack-plugin`, allowing for page-specific
customisation of the generated HTML template.

For example:

```
module.exports = {
  options: {
    mains: {
      index: {
        entry: './index',
        // Options here take priority over the preset's `html` options below.
        title: 'Site Homepage',
      },
      admin: {
        entry: './admin',
        title: 'Admin Dashboard',
      },
      account: {
        entry: './user',
        inject: true,
        template: './my-custom-template.html',
      },
    }
  },
  use: ['@neutrinojs/web', {
    // Customise the defaults used for all pages.
    html: {
      minify: false,
    }
  }]
}
```

For a list of the available `html-webpack-plugin` options, see:
https://github.com/jantimon/html-webpack-plugin#options

Fixes #865.
@edmorley edmorley added this to the v9 milestone Aug 21, 2018
@edmorley edmorley self-assigned this Aug 21, 2018
@@ -138,27 +138,34 @@ Neutrino({
### `options.mains`

Set the main entry points for the application. If the option is not set, Neutrino defaults it to:
Copy link
Member Author

@edmorley edmorley Aug 21, 2018

Choose a reason for hiding this comment

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

There is a lot of pre-existing duplication between api.md, creating-presets.md and customization.md that is out of scope for this PR, but something we should figure out how to avoid at some point.

},
set(newValue) {
value = newValue;
normalizedConfig = normalizeMainConfig(newValue);
}
});
});

this.mainsProxy = new Proxy(options.mains, {
Copy link
Member Author

@edmorley edmorley Aug 21, 2018

Choose a reason for hiding this comment

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

mainsProxy appears to be unused. Do we still need it?

Copy link
Member

@eliperelman eliperelman Aug 21, 2018

Choose a reason for hiding this comment

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

We need the Proxy itself, but only exposed it on the Neutrino API just in case. We can certainly remove it if we don't foresee exposing it as being useful.

Copy link
Member Author

@edmorley edmorley Aug 21, 2018

Choose a reason for hiding this comment

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

Nothing seemed to break when I removed it fwiw

@edmorley edmorley requested a review from eliperelman Aug 21, 2018
Copy link
Member

@eliperelman eliperelman left a comment

This looks perfect. Great job.

By default these main files are not required to be in JavaScript format. They may also potentially be JSX, TypeScript,
or any other preprocessor language. These extensions should be specified in middleware at
`neutrino.config.resolve.extensions`.


Copy link
Member

@eliperelman eliperelman Aug 21, 2018

Choose a reason for hiding this comment

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

Are there 2 blank lines here?

Copy link
Member Author

@edmorley edmorley Aug 21, 2018

Choose a reason for hiding this comment

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

Ah yes I'll remove this additional newline

@eliperelman
Copy link
Member

@eliperelman eliperelman commented Aug 21, 2018

I think this is still technically a breaking change since the value exposed by the API is now never a string.

@edmorley edmorley merged commit c03a8ca into neutrinojs:master Aug 21, 2018
2 checks passed
@edmorley edmorley deleted the mains-html-template-options branch Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants