tsconfig-paths-webpack-plugin icon indicating copy to clipboard operation
tsconfig-paths-webpack-plugin copied to clipboard

Support for references

Open sassanh opened this issue 5 years ago • 5 comments

It seems like this plugin doesn't support paths defined in references, so I'm suggesting adding this feature to the plugin.

sassanh avatar Feb 09 '20 15:02 sassanh

Sounds good! Fancy submitting a PR?

johnnyreilly avatar Feb 09 '20 16:02 johnnyreilly

I tried to find some time to do it but unfortunately no luck so far :(

sassanh avatar Feb 19 '20 10:02 sassanh

ts-loader has support for references:

const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin')

module.exports = {
  entry: './src/index.ts',
  mode: 'development',
  output: {
    filename: 'bundle.js',
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.js'],
    plugins: [new TsconfigPathsPlugin()],
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: 'ts-loader',
        options: { projectReferences: true },
      },
    ],
  },
}

chanced avatar Aug 11 '20 19:08 chanced

When webpack resolves modules, it should use the paths from these TS projects but only for the modules which belong to the project they're defined for.

To illustrate this, here's an example:

Project shared has these paths:

  "paths": {
    "helpers/*": ["./my-helpers/*"]
  }

Project app references project shared and has these paths:

  "paths": {
    "components/*": ["./my-components/*"]
  }

The components/* path defined by the app project should not be used for modules inside of the referenced project shared.

OliverJAsh avatar Jun 09 '21 15:06 OliverJAsh

Here is a reduced test case to demonstrate the problem: https://github.com/OliverJAsh/tsconfig-paths-project-references-bug

The paths inside the referenced project shared/tsconfig.json are not picked up at all.

OliverJAsh avatar Jun 11 '21 07:06 OliverJAsh