10up-toolkit
10up-toolkit copied to clipboard
Add option to customize config in a toolkit.config.js file instead of package.json
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
- [X] I agree to follow this project's Code of Conduct
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.