Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Pass computed default value to slate.config.js functions #756

Merged
merged 1 commit into from
Sep 14, 2018

Conversation

t-kelly
Copy link
Contributor

@t-kelly t-kelly commented Sep 14, 2018

What are you trying to accomplish with this PR?

With the config updates it is possible to set a config value as a function. This function had access to the SlateConfig instance, allowing you to fetch other config values:

// slate-tools.schema.js
module.exports = {
  'webpack.postcss.plugins': (config) => [
    autoprefixer,

    ...(process.env.NODE_ENV === 'production'
      ? [cssnano(config.get('webpack.cssnano.settings'))]
      : []),
  ]
};

However, one thing that was not possible to do was extend the default value of a config item. If the above config was the default value declared, and you wanted to add another PostCSS plugin while keeping the defaults, you would need to redeclare the default values plus add your own:

// slate.config.js
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const newPostCSSPlugin = require('newPostCSSPlugin');

module.exports = {
  'webpack.postcss.plugins': (config) => [
    newPostCSSPlugin,

    autoprefixer,

    ...(process.env.NODE_ENV === 'production'
      ? [cssnano(config.get('webpack.cssnano.settings'))]
      : []),
  ]
};

This approach requires you to add these libraries as new dependencies in your theme -- not cool.

Now, functions in your slate.config.js file have direct access to the default value, allowing you to extend it without needing to rewrite it:

// slate.config.js
const newPostCSSPlugin = require('newPostCSSPlugin');

module.exports = {
  'webpack.postcss.plugins': (config, defaultValue) => [
    newPostCSSPlugin,
    ..defaultvalue
  ]
};

@t-kelly t-kelly self-assigned this Sep 14, 2018
@t-kelly t-kelly merged commit 7aed317 into master Sep 14, 2018
@t-kelly t-kelly deleted the pass-default-computed-value branch September 14, 2018 14:54
@lock
Copy link

lock bot commented Oct 26, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant