Skip to content

Shared content base for multiple compiler instances #1283

@just-boris

Description

@just-boris

Modification Proposal

We have the following webpack config:

module.exports = ["foo", "bar"].map((theme) => {
  return {
    entry: "./src/index.js",
    output: {
      path: path.resolve(`dist/${theme}`),
    },
    resolve: {
      alias: {
        "~current-theme": path.resolve(`./src/themes/${theme}`),
      },
    },
  };
});

Webpack 4 handles such config perfectly allowing to see both themes on a single server via (/foo/main and /bar/main). With webpack 5 it no longer works (there is a single theme at /main).

This happened because of changes in getPaths implementation. Previously it allowed loose path matches.

Expected Behavior / Situation

There is a configuration option to set the base path for all entry points, so files will be resolved properly against each compiler

Actual Behavior / Situation

Currently there is no way to serve multiple compilations from a single server.

I created a demo project to with minimal scenario for this issue: https://github.com/just-boris/webpack-multi-entries/tree/webpack-5

Please paste the results of npx webpack-cli info here, and mention other relevant information

  System:
    OS: macOS 12.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 53.78 MB / 16.00 GB
  Binaries:
    Node: 14.19.2 - ~/n/bin/node
    Yarn: 1.22.15 - ~/n/bin/yarn
    npm: 6.14.17 - ~/n/bin/npm
  Browsers:
    Chrome: 101.0.4951.64
    Firefox: 91.9.0
    Safari: 15.5
  Packages:
    webpack: ^5.72.1 => 5.72.1
    webpack-cli: ^4.9.2 => 4.9.2
    webpack-dev-server: ^4.9.0 => 4.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions