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

Variables hot reloading #75

Open
franciscolourenco opened this issue Mar 19, 2018 · 6 comments
Open

Variables hot reloading #75

franciscolourenco opened this issue Mar 19, 2018 · 6 comments

Comments

@franciscolourenco
Copy link

franciscolourenco commented Mar 19, 2018

The variables seem to be updated, but only after restarting webpack dev server. postcss.config.js seems to be added as a loader dependency by default, which means that editing this file causes webpack to recompile. However the variable files imported in postcss.config.js don't. Is there a way to access the loader in postcss.config.js in order to call addDependency with the variable files?
Otherwise how is the reloading supposed to work?

@ai
Copy link
Member

ai commented Mar 19, 2018

Hi. You need to open issue in postcss-loader.

@ai ai closed this as completed Mar 19, 2018
@franciscolourenco
Copy link
Author

@ai postcss-simple-vars docs mention variable hot reloading. Is it currently not supported?

@ai
Copy link
Member

ai commented Mar 19, 2018

They are supported by postcss-loader. It reads a config. So I have no idea how to fix it in this plugin 🤷‍♂️

@franciscolourenco
Copy link
Author

One way to do it would be to receive file(s) path(s) instead of an object. That way you could you could do loader.addDependency('filepath'); require('filepath'); automatically and it would work.

@ai ai reopened this Mar 20, 2018
@ai
Copy link
Member

ai commented Mar 20, 2018

Yeap. I will think about it on next weekend.

@philipbordallo
Copy link

For anyone still having this issue, it's solvable by using the plugins option of postcss-loader, which gives you access to the loader context.

Example loader definition

{
  loader: 'postcss-loader',
  options: {
    plugins: function(loader) {
      const colors = require.resolve('./colors.js');
      loader.addDependency(colors);
      delete require.cache[colors];

      return [
        simpleVars({
          variables: function() {
            return require(colors);
          },
        }),
      ];
    },
  },
}

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

3 participants