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

How to exclude dirs from sass loader? #534

Closed
pohlaniacz opened this issue Mar 6, 2019 · 6 comments · Fixed by #540
Closed

How to exclude dirs from sass loader? #534

pohlaniacz opened this issue Mar 6, 2019 · 6 comments · Fixed by #540
Labels

Comments

@pohlaniacz
Copy link

Hi. I have dir like /uploads/ where user store their photos. When running webpack with enableSassLoader() it makes stat through all this files (which take long time). The only solution for now is to set "resolveUrlLoader: false" but I want to use it for simplier paths. So is there any solution to disable /uploads/ dir?

@Lyrkan
Copy link
Collaborator

Lyrkan commented Mar 6, 2019

Hi @pohlaniacz,

I think that's related to this issue: #428

Setting the attempts option of the resolve-url-loader to 1 could solve your issue (as explained here) while we update that loader to v3.x.

There is however no easy way to that right now... you have to change the config manually:

const config = Encore.getWebpackConfig();

for (const rule of config.module.rules) {
  if (rule.test && rule.test.toString() === '/\\.s[ac]ss$/') {
    for (const use of rule.oneOf.map(oneOf => oneOf.use)) {
      for (const loader of use) {
        if (loader.loader === 'resolve-url-loader') {
          loader.options.attempts = 1;
        }
      }
    }
  }
}

module.exports = config;

Or after #509 is released:

Encore.configureLoaderRule('sass', rule => {
  for (const use of rule.oneOf.map(oneOf => oneOf.use)) {
    for (const loader of use) {
      if (loader.loader === 'resolve-url-loader') {
        loader.options.attempts = 1;
      }
    }
  }
})

@pohlaniacz
Copy link
Author

damn, thanks, works like a charm! FYI, on intel with 12 cores from E5-1650, 4x16gb ram and 2 ssd disk it took more than 15 minutes (I've stopped it after that, so don't know how long should I wait). After your fix it take ~5 seconds ;) Very strange that I can't easily include/exclude dirs or your fix isn't an option. Thanks again!

@Lyrkan
Copy link
Collaborator

Lyrkan commented Mar 7, 2019

Wow, I didn't think the difference would be that big, you must have a lot of files.

The loader doesn't provide an include/exclude mechanisme, how it behaves in that version is a bit weird and you can only limit the amount of folders it'll process (through the attempts option).

options.attempts = 1 would probably be a better default value but since it could break some builds I'd rather update the resolve-url-loader to its latest version which removes this magic beahvior.

As for the fix given in my previous answer, it isn't an option simply because we don't have something like Encore.configureResolveUrlLoader(...) (yet). That could change in the future though.

@pohlaniacz
Copy link
Author

I'd rather update the resolve-url-loader to its latest version which removes this magic beahvior.

what do you mean? I think I have the latest version of webpack-encore and only way to "fix" this is resolveUrlLoader: false and turn off resolving url() ?

@Lyrkan
Copy link
Collaborator

Lyrkan commented Mar 7, 2019

What I meant is that Encore is using a dependency called resolve-url-loader, currently in version 2.x.

This version does some dirty things behind the scene to generate the right paths in your CSS files as described in #428.

There is a more recent 3.x version that uses a cleaner algorithm to determine those paths.

So, instead of adding attempts: 1 to the default options of the resolve-url-loader in Encore (which is what the "fix" above does) it would probably be a better idea to make it use resolve-url-loader 3.x (that's not something that you can do, but something we have to change on our side).

@pohlaniacz
Copy link
Author

ah, ok, now it's clear. Anyway, thanks again for help! Best wishes.

@Lyrkan Lyrkan added the HasPR label Mar 15, 2019
weaverryan added a commit that referenced this issue Mar 25, 2019
…Plugin (Lyrkan)

This PR was merged into the master branch.

Discussion
----------

Update various dependencies and remove the LoaderOptionsPlugin

This PR updates various dependencies that were either really outdated or subject to security issues.

Since most of those packages are listed in our dev dependencies it shouldn't have a big impact on most users, but the following changes could be an issue for some of them:

* The `css-loader` was updated from `^1.0.0` to `^2.1.1` ([breaking changes](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#200-2018-12-07))
* The `resolve-url-loader` was updated from `^2.3.0` to `^3.0.1` ([breaking changes](https://github.com/bholloway/resolve-url-loader/tree/master/packages/resolve-url-loader#version-3), closes #428 and closes #534)
* The minimum version of NodeJS was bumped from 6 to 8 (needed to update `zombie`, and v6's end-of-life happening in less than a month anyway)
* The [`LoaderOptionsPlugin`](https://webpack.js.org/plugins/loader-options-plugin/) was removed since it should not be needed anymore and caused a *really annoying* bug when used with the latest version of the `resolve-url-loader` (see #428 (comment))

Commits
-------

aeea89b Update various dependencies and remove the LoaderOptionsPlugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants