webpack-chain icon indicating copy to clipboard operation
webpack-chain copied to clipboard

How to configure multiple pages?

Open jujubone opened this issue 6 years ago • 8 comments

config .entry('index') .add({ pageOne: './src/pageOne/index.js', pageTwo: './src/pageTwo/index.js', pageThree: './src/pageThree/index.js' }) .end() This is error

jujubone avatar Mar 10 '18 06:03 jujubone

Hi!

Multiple entrypoints and/or multi-main entries are defined like so:

config
  .entry('index')
    .add('src/index.js')
    .end()
  .entry('a-second-page')
    .add('src/foo.js')
    .add('src/bar.js')
    .end();
  .entry('a-third-page')
    .add('src/baz.js');

If there's a way to make this clearer in the docs we'd more than gratefully accept a PR if you had a spare moment? :-)

edmorley avatar Mar 10 '18 22:03 edmorley

@edmorley Thank you very much for your answer. My English is not very good, so there is nothing I can do to enhance the docs. I'm sorry.

jujubone avatar Mar 11 '18 04:03 jujubone

Hi @edmorley I am wondering how to configure multi-main entries with different html template, could you guide me?

Very thankful.

zen-li avatar Mar 19 '18 08:03 zen-li

@zen-li In Neutrino we do the following:

https://github.com/mozilla-neutrino/neutrino-dev/blob/5b78b4134489a667e72d366c7b4b3a3f357315e0/packages/web/index.js#L119-L134

The process here is to create an entry and an instance of html-webpack-plugin/template for every main entry you have.

['index', 'admin'].forEach(page => {
  config.entry(page).add(`src/${page}`);

  config.plugin(`html-${page}`).use(HtmlWebpackPlugin, [{
    filename: `${page}.html`
  }]);
});

eliperelman avatar Mar 19 '18 11:03 eliperelman

Thanks @eliperelman , that was very helpful.

zen-li avatar Mar 20 '18 12:03 zen-li

Actually, keeping open for docs.

eliperelman avatar Mar 27 '18 15:03 eliperelman

For those wanna replace whole entry, can do:

const page = 'login'
config.entryPoints.clear()
config.entry(page).add(`src/${page}`)

up9cloud avatar Feb 28 '19 22:02 up9cloud

@eliperelman what documentation would you like to write?

yordis avatar Jul 07 '19 05:07 yordis