Skip to content

[postcss.config.js] Inefficient config loading #307

Closed

Description

@s-panferov

Hello. I have a quite complex setup for PostCSS loader and I want to use happypack, so I'm forced to use a postcss.config.js file to configure postcss-loader.

I have a single postcss.config.js file in my project with a stable content. I use options to configure it at the first time, but then it remains the same all the time. But I found out that postcss-loader doesn't cache my config file and recreates all the configuration for every single file in the project. This slows down my build time for about 10 seconds.

This can be solved either by:

  1. Add some option to force config file caching.
  2. Allow to overwrite config lookup algorithm.

Activity

  1. michael-ciniawsky commented on Oct 26, 2017

    @michael-ciniawsky
    Contributor

    cosmiconfig caches the file by default to avoid repetitive fs calls. The config needs to be evaluated for each file, bc of the context when using a {Function}. Do you have a concrete solution for one of our proposed solutions in mind ? Does your build time decline when using a fixed path to the config file ?

  2. s-panferov commented on Oct 26, 2017

    @s-panferov
    Author

    @michael-ciniawsky

    Yes, I have a fixed path to a config file. The main problem is evaluation, not reading from a file system.

    The simplest solution is to take this function from options. This would allow me to write a simple caching decorator.

  3. michael-ciniawsky commented on Oct 26, 2017

    @michael-ciniawsky
    Contributor

    What do you mean by remove :) ? If there is a way to refactor with the current logic staying in place but improved caching/memoization feel free to open a PR. Otherwise I'm afraid this is won't fix

  4. s-panferov commented on Oct 26, 2017

    @s-panferov
    Author

    @michael-ciniawsky I haven't used the word remove :) Ok, I'll send a PR today

  5. michael-ciniawsky commented on Oct 26, 2017

    @michael-ciniawsky
    Contributor

    I haven't used the word remove :)

    Then I misunderstood your intend 😛

    Ok, I'll send a PR today

    kk

  6. changed the title [-]Inefficient config loading[/-] [+][postcss.config.js] Inefficient config loading[/+] on Oct 30, 2017
  7. michael-ciniawsky commented on Oct 30, 2017

    @michael-ciniawsky
    Contributor

    Did you find a solution ?

  8. michael-ciniawsky commented on Nov 28, 2017

    @michael-ciniawsky
    Contributor

    I have something in mind but this needs to be done in postcss-load-config instead with the next upgrade (memoize the config {Function}), I will leave the issue open for tracking purposes

  9. simonbuchan commented on Jan 24, 2018

    @simonbuchan

    Sounds like OP wants something like babel 7's caching api for .babelrc.js. Essentially:

    module.exports = api => {
      const a = api.cache(() => aExpr);
      const b = api.cache(() => bExpr);
      ...
    };

    now babel only needs to evaluate aExpr and bExpr for each file. There's a bunch more detail, but no docs yet, other than the error you get when it's not configured: https://github.com/babel/babel/pull/5608/files

  10. michael-ciniawsky commented on Jan 24, 2018

    @michael-ciniawsky
    Contributor

    @simonbuchan Thx I will definitely look into it :). Should be similar to memoizing the {Function} calls in postcss-load-config, but I will check what they did aswell 😛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions