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

Allow sw-precache CLI to read config from package.json #152

Closed
jeffposnick opened this issue Aug 11, 2016 · 5 comments
Closed

Allow sw-precache CLI to read config from package.json #152

jeffposnick opened this issue Aug 11, 2016 · 5 comments

Comments

@jeffposnick
Copy link
Contributor

It's a common practice supported by other build tools with CLIs, e.g. eslint.

@addyosmani
Copy link
Contributor

Given we support --config=path/to/sw-precache-config.json, do you feel it would make sense to support just a single place for config (either package.json or the external json file) or is the goal short-term to try supporting both?

@jeffposnick
Copy link
Contributor Author

I don't know. 😦

I'm not happy with the current approach to option parsing in the CLI in general (see #120) and I'm thinking of taking a survery of some major build tools with CLIs (browserify, webpack, eslint, etc.) and see if there's a canonical dependency or pattern that they all use for reading and parsing options.

I'm personally happy with --config, but maybe there's a strong use case for package.json as an additional option? I'd like to research more and am open to feedback!

@addyosmani
Copy link
Contributor

Looking at a few popular CLI tools:

create-react-app seems to use minimist under the hood (we do too via meow): https://github.com/facebookincubator/create-react-app/blob/master/global-cli/index.js#L43

Webpack seems to use https://www.npmjs.com/package/yargs

ESLint seems to use opinionator: https://github.com/gkz/optionator (I've never used this before)

@sindresorhus
Copy link

Many tools use pkg-conf to read config from package.json. It's much nicer to be able to specify config in package.json than having to supply CLI flags on every run or creating a npm run script just to persist the flags.

@jeffposnick
Copy link
Contributor Author

We've started explicitly recommending using objects exposed via module.exports from a standalone JS file for external configuration. I prefer that approach, since there are configuration options that take values which aren't easy to express when serialized to JSON.

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

No branches or pull requests

3 participants