NormalModuleReplacementPlugin is not working for replacing node_modules scss file with another scss file in assets

Viewed 241

_bg-theme.scss file is installed in node_modules after adding a package in package.json

I am trying to replace node_modules scss file with the scss file(_bg-theme.scss) we added in assets folder bg-theme.scss .

I am using webpack.NormalModuleReplacementPlugin but its not working.

webpack.common.js

 plugins: [
     new webpack.NormalModuleReplacementPlugin(
          /\/node_modules\/@bg-file-menu\/core\/dist\/styles\/mixins\/_bg-theme.scss/,
          '../../../src/web/assets/styles/bg-theme.scss',
        )
  ]

What is the correct way to fix this. Any suggestion or solution is appreciated.

1 Answers

The second path (your assets file) is relative to the first. So you'd have to go a few more levels up.

plugins: [
 new webpack.NormalModuleReplacementPlugin(
      /\/node_modules\/@bg-file-menu\/core\/dist\/styles\/mixins\/_bg-theme.scss/,
      '../../../../../../../src/web/assets/styles/bg-theme.scss',
    )

]

Related