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

Aperta
#187 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

  • #188 di @kmcaloon — chiusa senza merge

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
30/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript
Ambito
build-system

Direzione di ricerca

Inizia in utils/config.js, da getTenUpScriptsConfig(), quindi esamina come package.json, filenames.config.js e un webpack.config.js personalizzato forniscono attualmente la configurazione. Definisci il comportamento previsto di toolkit.config.js e verifica che le entry dinamiche raggiungano il resto del processo di build senza perdere la configurazione predefinita esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

[Type] Enhancement
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
Lingua principale
JavaScript
Stelle
147
Fork
21
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di 10up/10up-toolkit

Tutte le issue di 10up/10up-toolkit

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.