Webpack 2: How to exclude all node_modules except for

后端 未结 4 1883
闹比i
闹比i 2021-01-18 01:01

I need to have babel run on /node_modules/identicons/ However I still want to exclude all other packages.

Reason is the identicons package

相关标签:
4条回答
  • 2021-01-18 01:30

    You could exclude everything from node_modules that is not identicons:

    exclude: /node_modules\/(?!identicons$)/
    
    0 讨论(0)
  • 2021-01-18 01:34

    Another way:

    exclude: [
      {
        test: [
          path.resolve(__dirname, './node_modules'),
        ],
        exclude: [
          path.resolve(__dirname, './node_modules/MODULE_TO_INCLUDE'),
          path.resolve(__dirname, './node_modules/ANOTHER_MODULE_TO_INCLUDE'),
        ]
      }
    ]
    

    It worked for me.

    0 讨论(0)
  • 2021-01-18 01:38

    Exclude whole node_modules folder, except required module:

    {
      test: /\.js$/,
      exclude: /node_modules\/(?!identicons\/).*/,
    }
    

    https://github.com/webpack/webpack/issues/2031#issuecomment-219040479

    0 讨论(0)
  • 2021-01-18 01:46

    I think you can use regex, something like

    exclude: [
      /node_modules\/(?!identicons).*/
    ]
    
    0 讨论(0)
提交回复
热议问题