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

Provide way to use neutrino-middleware-html-template multiple times #326

Closed
edmorley opened this issue Sep 22, 2017 · 4 comments
Closed

Comments

@edmorley
Copy link
Member

edmorley commented Sep 22, 2017

For Treeherder, we have a multi-page app that needs to use different custom templates for each page, rather than the stock template generated by html-webpack-plugin / html-webpack-template.

In our Neutrino v4 config there's a lot of unnecessary duplication:
https://github.com/mozilla/treeherder/blob/5c0c7eb5e241638bc1d636cce2468d568e374ce2/neutrino-custom/base.js#L96-L145

At the same time as upgrading to Neutrino v6, this has been reduced down to roughly:

    (neutrino) => {
      // Remove the default entry point and html plugin
      neutrino.config.entry('index').delete(neutrino.options.entry);
      neutrino.config.plugins.delete('html');

      const entries = ['index', 'perf', 'logviewer', 'failureviewer', 'userguide'];

      entries.forEach(entry => neutrino.config
        .entry(entry)
          .add(join(neutrino.options.source, `entry-${entry}.js`))
          .end()
        .plugin(`html-${entry}`)
          .use(HtmlPlugin, [{
              filename: `${entry}.html`,
              template: join(neutrino.options.source, `${entry}.html`),
              // The vendor/runtime chunk names here must match those in neutrino-middleware-chunk.
              chunks: [entry, 'vendor', 'runtime'],
              // Copied from neutrino-middleware-html-template
              minify: {
                useShortDoctype: true,
                keepClosingSlash: true,
                collapseWhitespace: true,
                preserveLineBreaks: true
              },
          }])
      );
    },

Whilst this is an improvement on how it was before, it still has to duplicate the minify options from neutrino-middleware-html-template.

Ideally I'd be able to just .use() the middleware multiple times (passing the options I need to override for each), and be able to override the plugin entry name for each, to avoid the html name collision.

Is there a way to do this that I'm missing or else would adding support for customising the names be possible?

@eliperelman
Copy link
Member

There is not currently a way to do this, but this is something I've thought about before. I think the best solution would be to probably allow middleware to accept through its options what its name or ID should be, e.g.:

neutrino.use(middleware, {
  ...otherOptions,
  pluginId: 'alpha'
});

I also think this should be managed at the middleware level, since some middleware can generate many pieces of identifiable configuration, and it's possible you may want to allow configuring multiple names via middleware options:

neutrino.use(middleware, {
  alpha: {
    pluginId: 'beta'
  },
  gamma: {
    pluginId: 'delta',
  }
});

@eliperelman
Copy link
Member

I've got a patch in the v7 branch that will allow doing this, although it's not documented yet.

0f037d8

@edmorley
Copy link
Member Author

Many thanks for that and the others! :-)

@eliperelman
Copy link
Member

Leaving open to document this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants