knip icon indicating copy to clipboard operation
knip copied to clipboard

💡 Automatically pick up `resolve.alias` in webpack

Open fregante opened this issue 1 year ago • 1 comments

Suggest an idea for Knip

I have this configuration in my webpack.config.js:


    alias: {
      // Not needed in this build
      handlebars: false,

      // https://github.com/webpack/webpack/pull/12693#issuecomment-914079083
      filenamify: "filenamify/browser",

      // Silently improve tree-shakeability and AMD-related errors 
      lodash: "lodash-es",

      // Lighter jQuery version
      jquery: "jquery/dist/jquery.slim.min.js",
    },

In which every lodash import is mapped to lodash-es. This doesn't seem to be picked up by knip, which requires either ignoreDependencies or paths: https://knip.dev/reference/configuration#paths

Can this field be automatically picked up instead? Both for local aliases and node_module aliases

fregante avatar Feb 09 '25 12:02 fregante

If you (or someone else) could think of a solution, pull requests to add this are welcome.

webpro avatar Feb 10 '25 08:02 webpro

Knip v5.54.0 respects resolve.alias (by translating them to compilerOptions.paths, but does not do the mapping/swapping thing.

So I'm going to close this one, we can keep #950 open for that RFC.

webpro avatar May 06 '25 07:05 webpro