-
Notifications
You must be signed in to change notification settings - Fork 213
Support per-page HTML template customisation via 'mains' #1029
Support per-page HTML template customisation via 'mains' #1029
Conversation
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.
@@ -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: |
There was a problem hiding this comment.
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, { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks perfect. Great job.
docs/creating-presets.md
Outdated
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`. | ||
|
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
I think this is still technically a breaking change since the value exposed by the API is now never a string. |
This adds support for defining each entry point in
mains
as an object, where the path to the entry point is now defined under anentry
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 tohtml-webpack-plugin
, allowing for page-specific customisation of the generated HTML template.For example:
For a list of the available
html-webpack-plugin
options, see:https://github.com/jantimon/html-webpack-plugin#options
Fixes #865.