Skip to content

Latest commit

 

History

History
63 lines (54 loc) · 952 Bytes

File metadata and controls

63 lines (54 loc) · 952 Bytes

Multiple apps

webpack.config.js

module.exports = {
  entry: {
    app: './js/app/index.js',
    header: './js/header/index.js',
  },
  mode: 'production',
  output: {
    path: './dist',
    filename: '[name].js',
    libraryTarget: 'umd',
  },
  rules: [{
    test: /\.js$/,
    use: {
      loader: 'babel-loader',
    },
  }],
  plugins: [
    new HtmlWebpackPlugin({
      template: './templates/index.html',
    }),
    new Plugin({
      app: '#app-root',
      header: '#header-root',
    }),
  ],
};

templates/index.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head></head>
  <body>
    <div id='header-root'></div>
    <div id="app-root"></div>
  </body>
</html>

js/app/index.js

export default () => '<h1>Hello world!</h1>';

js/header/index.js

export default () => `<nav>
  <a href="/">Home</a>
  <a href="/about/">About</a>
</nav>`;