Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

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

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

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

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

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

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

Copy link
Member

@eliperelman eliperelman left a 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.

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

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

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

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
@edmorley edmorley deleted the mains-html-template-options branch August 21, 2018 15:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

2 participants