extract-loader icon indicating copy to clipboard operation
extract-loader copied to clipboard

Doesn't work with aliases properly

Open wizardion opened this issue 4 years ago • 3 comments

When WebPack has aliases propery:

module.exports = {
...
resolve: {
    extensions: ['.js'],
    alias: {
      default: path.resolve(__dirname, 'default'),
      './default': path.resolve(__dirname, 'default'),
    }
  }
}

and extract-loader is being used with an html-loader

module.exports = {
...
module: {
    rules: [
      {
        test: /\.html$/,
        use: [
          {
            loader: 'extract-loader',
          },
          {
            loader: 'html-loader',
          }
        ]
      }
    ]
}
...
}

end temple that uses aliases default:

<img src="default/course-default.jpg" />
...
<img src="images/logo.svg" alt="">

extract-loader - gives me an error:

Error: Cannot find module './default/course-default.jpg' from '/webpack-demo/src'

But with the same configuration and old version "extract-loader": "^2.0.0" - everything is working just fine! Is there something wrong happening with the extract-loader?

wizardion avatar Apr 21 '20 20:04 wizardion

@wizardion I ran into the same issue, caused by extract-loader attempting to resolve requires without considering aliases.

I forked the repo and fixed this issue - you can always try and giving it a spin to see if it works for you as well.

vseventer avatar Apr 23 '20 01:04 vseventer

@vseventer I resolved my problem by getting rid of this horrible extract-loader in my main HTML file template. The extract-loader also brokes my AngularJS templates in my project. I used it only for ejs variables in my main HTML template, within such configuration:

module: {
    rules: [
        {
            test: /\.html$/,
            use: [
                "ejs-loader",
                "extract-loader",
                "html-loader"
            ]
        }
    ]
}

So I changed the main template of my application to *.ejs file extension to allow my HtmlWebpackPlugin to serve the the ejs variables and got rid of extra loaders. The "html-loader" is still in use for all other HTML files in my project.

But the main issue with this loader is still present, and I don't know why it's not going to be fixed for so long time... 'cause this issue exists from v3.0.0. It's frustrating by spending so much time figuring out for just a simple problem.

wizardion avatar Apr 23 '20 12:04 wizardion

Can we get this PR merged in and released? I'm having the same alias issue.

boroth avatar May 19 '21 22:05 boroth