Search code examples
javascriptwebpackwebpack-4

Webpack: 'Cannot find module' issue when using webpack.ignorePlugin


In my code, I have an import statement as following:

import '../theme/src/fonts/dist/_icons.scss'

What I want to realize is, I don't want to import this file when in building state, which means in build phase I want to ignore this statement. So I use webpack.ignoreplugin, and my setting is as below:

...,
plugins: [
    ...,
    new webpack.IgnorePlugin(/^\.\.\/theme\/src\/fonts\/dist\/_icons\.scss/, /binder$/),
    ....
]

Well, in my built out files the icons.scss is not imported, which means it's being ignored. But when I open the built out files it has following error:

throw new Error("Cannot find module \"../theme/src/fonts/dist/_icons.scss\"")

So anything wrong in my using webpack.ignorePlugin?


Solution

  • I generate an empty scss file, then I use an alias, '../theme/src/fonts/dist/_icons.scss': emptyScssfilepath, so the build will use this empty scss file instead.