Every time I'm working on a (p)react PoC codebase, I wish there was a CLI that just allowed me to say CLItoolname entryfile outputfile and not bother with any of the webpack, babel, etc. cruft that is completely irrelevant to build a bog standard bit of "it uses ES6, it uses JSX, it needs to become something I can load in the browser".
Would it make sense to offer a CLI tool with preact that achieves that? And if it needs to install babel, webpack, etc. as part of its dependency tree, that's cool, but there is nothing about those things I should have to configure if I just want to compile the kind of code that the README.md shows.
(Note that this is drastically different from a "preact-start-project" or the like: I just need to write some quick PoC code, with a tool that'll bundle that PoC code, so I'm not looking for full framework-based project bootstrappers)
It sounds like https://github.com/insin/nwb#quick-development :)
Hi there - we released preact-cli for exactly this reason! It's a one-command, one-dependency bundling tool that bakes in all the best practises and produces awesome code-splitted bundles with no configuration at all. It also handles rendering and debugging stuff for you - you just export your root component.
Here the entire project setup process:
# Install it (once and you're good):
npm i -g preact-cli
# create a new project:
preact create my-great-app
cd my-great-app
# start a live-reload (HMR) dev server:
npm start
# go to production:
npm run build
FWIW I only just realised we never even added a link to Preact CLI in the Preact readme - really need to, haha.
@developit =D
Also I'd advocate telling people to use npx, because with npx there is literally no reason to ever install anything globally ever again:
# make sure you have npx installed
npm i -g npx
# install preact-cli
npm i preact-cli
# run preact-cli!
npx preact-cli entryfile outputfile
As noted above, the preact-cli project resolves this and it is now prominently mentioned in the project's README.
@robertknight shouldn't the getting started guide also mentioned the CLI?
Yes - I updated the readme, and we could effect those changes on the website too.
Regarding npx, that looks nice! preact-cli does kinda need to be global though, since you run preact create <name> to initialize a new project and it does all the setup for you. It installs itself as a local devDependency of the project and that gets used for all the building and whatnot, but in order for preact create to work it'll need to be global *
_* or in the parent directory of the place you're creating a project, but that's sortof the same as a global._
FWIW I use this bash alias to run stuff out of node_modules so preact-cli and gzip-size-cli are kinda the only tools I have installed globally:
# npm-exec webpack -p
alias npm-exec='PATH=$(npm bin):$PATH'
Most helpful comment
As noted above, the preact-cli project resolves this and it is now prominently mentioned in the project's README.