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

Add option to customize config in a toolkit.config.js file instead of package.json #187

Open
1 task done
kmcaloon opened this issue Apr 15, 2022 · 1 comment
Open
1 task done

Comments

@kmcaloon
Copy link

Is your enhancement related to a problem? Please describe.

I was wondering what is behind the choice of allowing developers to modify the toolkit configuration via package.json and filenames.config.js instead of having something like a toolkit.config.js at the project root?

For my specific use case, I am trying to implement dynamic entries but modifying just the entry within a custom webpack config isn't enough because other functions throughout the build process rely on getTenUpScriptsConfig() to return the entries. Maybe there might be other use cases where it would be handy having the entire toolkit configuration customizable with js?

I didn't want to create a PR because I'm sure you have your reasons for the current structure, but I am able to easily accomplish what I'm looking for by making the following change to utils/config.js:

/**
 * Returns 10up-scripts config either from package.json or toolkit.config.js with default values
 *
 * @returns {object}
 */
const getTenUpScriptsConfig = () => {
  
  const packageJson = getPackage();
  const configJS = 'toolkit.config.js';
  const config = packageJson['10up-toolkit'] || packageJson['@10up/scripts'] || hasProjectFile(configJS) && require(fromProjectRoot(configJS));
  const defaultConfig = getDefaultConfig();

  if (!config) {
    return defaultConfig;
  }

  return {
    // override default configs with user-defined config
    ...defaultConfig,
    ...config,
    // these properties must be merged
    filenames: {
      ...defaultConfig.filenames,
      ...config.filenames,
    },
    paths: {
      ...defaultConfig.paths,
      ...config.paths,
    },
  };
};
   

Designs

No response

Describe alternatives you've considered

As mentioned, I've also tried modifying a custom webpack.config.js at the project root but it doesn't allow for the dynamic entries to be piped into the rest of the build process.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@nicholasio
Copy link
Member

In the past, we had a buildfiles.config.js but I'm pretty sure we're ignoring this file right now. https://github.com/10up/10up-toolkit/blob/develop/packages/toolkit/config/buildfiles.config.js

I actually like the idea of a single toolkit.config.js file and I'd be open to merging support for it if you submit a PR. I'd still like to support package json config though.

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

Successfully merging a pull request may close this issue.

2 participants