Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack alias false on directories / expressions #1317

Closed
mmarton opened this issue Jun 2, 2021 · 5 comments
Closed

Webpack alias false on directories / expressions #1317

mmarton opened this issue Jun 2, 2021 · 5 comments

Comments

@mmarton
Copy link

mmarton commented Jun 2, 2021

Related to #1291
Aliasing individual files to false to prevent resolving works fine for individual files. But unfortunately not for directories / expressions

  • Operating System: linux mint 20
  • Node Version: 15.11
  • NPM Version: 7.6 (but I use yarn: 1.22.5)
  • webpack Version: 5.38.1
  • css-loader Version: 5.2.6

Expected Behavior

According to the webpack doc I could alias directories or regular expressions to someting.
https://webpack.js.org/configuration/resolve/#resolvealias

{ xyz: 'modu/dir' } /abc/node_modules/modu/dir/index.js /abc/node_modules/modu/dir/file.js
{ xyz$: 'modu/dir' } /abc/node_modules/modu/dir/index.js /abc/node_modules/xyz/file.js

Aliasing these to false doesn't work with css-loader

Actual Behavior

Code

const path = require('path');
module.exports = {
    entry: './index.css',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'build.css'
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: {loader: 'css-loader'}
            }
        ]
    },
    resolve: {
        alias: {'/assets/': false}
    }
}```

```css
.logo {
    background-image: url(/assets/logo.png);
}
@alexander-akait
Copy link
Member

Expected, /assets/logo.png is not module, /assets/ will not work with JS too

@mmarton
Copy link
Author

mmarton commented Jun 17, 2021

:( ok, is it good as a feature request or sould i close it?

@alexander-akait
Copy link
Member

Give me minute I will look at this

@alexander-akait
Copy link
Member

Oh I see, here the same problem (#1246, description is different, but internally problem only here), we need major release for this (we are already working on it), right now I recommend to use https://github.com/webpack-contrib/css-loader#function

But here note - resolve.alias will not work here, because it works on with explicit module, but you want to ignore whole directory, but we have other plugin:

new webpack.IgnorePlugin({ resourceRegExp: /\/assets\// })

but it will work only after we fix #1246

So let's close in favor #1246

I think we will do major release in near future (maybe the next week or next week after the next week 😄 )

@mmarton
Copy link
Author

mmarton commented Jun 17, 2021

That's exactly what I want to do. I have a (symlinked) static folder under the docroot that I don't want to be processed (and duplicated in the build folder by webpack)
The callback works I'll go with config.url = url => !url.startsWith('/static/'); until this will be released.

tanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants