Zero-config modern front-end web app template, with Webpack (bundler), Babel (compiler), Eslint/Airbnb (strict code style linting), Jest (unit tests), and D3 (data visualization) – all pre-configured and ready to go. You just add your code! You don't have to configure a thing (except when you want to deploy to remote server).
ES6, ES2018 and beyond – via Babel (and the syntax is picked up by Sublime/VS Code editors):
- Export/Import
- Tagged templates
- Async functions
- Await operator
- Spread operator
- Generator functions
- Map/Set objects
- WeakMap/WeakSet objects
- Object getters/setters
- Optional chaining
- and more...
The project template uses a strict, highly disciplined Javascript code style (via Eslint/Airbnb). Please see Airbnb code style defaults here. When using Eslint/Airbnb, the code style will be virtually in-distinguishable from one developer to another (code quality may be different matter...). By enforcing a strict code style, the "mental friction" of getting into a new project is greatly reduced.
As you are coding, lint issues show up in real time in Sublime and VS Code (when configured for linting), so you can fix lint errors right then and there.
In some cases you'll have to override the strict linting rules, which is easy to do. This template project uses several such overrides.
To do a lint check of your project, run the command npm run lint
or yarn lint
.
Project
|- .babelrc (Babel compiler settings)
|– .eslintrc.json (Eslint linter settings)
|- .git
|- .gitignore
|- LICENSE.txt (MIT)
|- README.md (this file)
|- dist (distribution directory, can be rsync'ed somewhere else)
| |- bundle.js (generated by Webpack, and included by index.html)
| |- favicon.ico (static file)
| |- index.html (static file)
|- node_modules
|- package.lock.json
|- package.json
|- src (code, tests and css go here)
| |- index.js (entry point)
| |- module.js
| |- module.test.js
| |- styles.css
|– webpack.config.js (Webpack bundler settings)
build-dev
- Uses Webpack for a development build
build-prod
- Uses Webpack for a production build
clean
- Removes the ./dist/build.js
file
deploy
- Deploys the app to an external server (using ssh/rsync, requires configuration)
lint
- Lints the ./src/js
files using Eslint
start-dev-server
- Starts the Webpack dev server
start-server
- Starts a static server (using http-server)
start-remote-server
- Starts a remote static server (http-server) in the background
test
- Runs Jest on the test files in ./src/js
- Node: ^14.2.0
- Npm: ^6.14.4
- Yarn: ^1.22.4 (it is not required to use Yarn, but it's is a convenient alternative to Npm)
- Make sure that you have recent versions of
node
(node --version
) andnpm
(npm --version
), and optionallyyarn
(yarn --version
) on your system, see above. If not, find other resources on the web on how to install these utilities on your system - Decide on a name of your new front-end project
- Log in to Github (or sign up). Without logging in, the following steps will not work
- Go to this repo and then click the green Use this template button above and use the name for your new the repository name, decide on whether to make your repo public or private, then click the green Create repository from template, after which your new repository is created on GitHub
- Clone the repo to your local system (see Github instructions if needed)
- Install the dependencies by running
npm install
(or justyarn
) - To run any of the commands listed below do
npm run <command>
, oryarn <command>
- Start the dev server by running the
start-dev-server
command - With your browser, head to
http://localhost:8080
and open the browser's debugger - Verify that you see the similar logs in the browser console output as the section below, and that you see no errors. If you don't see the expected output or if you see errors, revisit your steps
Testing Babel...
default export/import works
non-default export/import works
template string works
tagged template works
arrow works
arrow iife works
async function works
async iife works
spread works
generator works
Map works
Set works
WeakMap works
WeakSet works
getter works
setter works
optional chaining works
async/await works
- Run the command
test
to test the unmodified project. If the tests don't run clean, again please retrace your steps - Run the command
lint
to verify that there are no lint errors in the unmodified project. If you see errors, again retrace your steps - If you see any errors when compiling/running the app, testing or linting it, there is no point in proceeding further. Please retrace your steps
- If you don't plan to use D3 in your project, do the following
- Remove the
d3
dependency in thepackage.json
file, - Remove any references to
d3
in the./src/index.js
file - Do
rm -rf node_modules
- Re-install the now-slimmed dependencies by running
npm install
(or justyarn
)
- Properly configured Sublime and VS-Code editors will pick up the Eslint/Airbnb settings and show you lint errors immediately in the editor
- Keep the Webpack dev server running (by using the
start-dev-server
command) while working on your project. You'll see Webpack's hot reloading in action, meaning that you won't have to manually reload the app to see code changes as you save them in your editor (as the app is auto-reloaded upon save) - In general while developing the project, make frequent saves and inspect the app as it is being reloaded after each save. Also do frequent git commits (and push to origin)
- Modify the
README.md
file to describe your project - Change the
favicon.ico
image file in the project root to an icon of your liking - Modify the
./dist/index.html
file to your needs (but don't change thescript
tag, nor thelicense
reference) - Modify the
./src/index.js
and./src/styles.css
to your needs. The./src/module.js
is there only to demonstrate thatimport/export
works, so remove it (and the associated test) if not needed. You can/should add other files as your app grows, and those new files need to useexport
of whatever symbols other files need toimport
and use. Please see MDN and other web resources for howimport/export
works - While in development mode, full source maps are produced so you can debug effectively in the browser's debugger (for example setting breakpoints)
- When ready to build a production bundle, run the command
build-prod
. This will produce a smaller, minified version of the app, which will load faster - To view the production build in action, run the command
start-server
. In it's default configuration, it makes the app available atlocalhost:8000
Please note: Setting up deployment is not zero-config
- If you have a public server somewhere on the internet, ensure that you have set up
ssh
access to that system, and thatrsync
works. - If you don't have a working
ssh
connection to your remote system, find other resources on the web on how to set upssh
, then verify that you can login to your remote system overssh
, then return here. No point in proceeding if you don't havessh
working - In most Linux type systems,
rsync
is available and running by default. If not, please see other web resources how to getrsync
working on your remote system - Head to your remote system with
ssh
and create a directory for the app somwhere under your user directory - Make sure that you have required versions of
node
,npm
, andyarn
(please see required versions above) and that they are installed globally on the remote system. If not, see other resources on the web for how to install these required dependencies. Do such install(s), and then return here. Please do not proceed until you've verified that these dependencies are available from the command line on your remote system - Exit from your remote system
- On your local system, modify the
deploy
command in thepackage.json
file to set the correct path argument torsync
to the just-created remote directory. Please note that the initialdeploy
command in package.json ("deploy": "rsync -rzv --exclude 'node_modules' . username@host:/path-from-user-dir-to-project"
) is a placeholder and must be modified - Test and lint your project again locally (please see 'Developing your project' above), and fix any remaining issues before proceeding
- Run the command
build-prod
to produce a production bundle in the local./dist
directory - Fire up the production bundle locally, using the
start-server
command described above - Verify that the production app behaves as expected. If it doesn't, there is no point in proceeding
- Deploy your app to the remote server by using the
deploy
command. If you havessh
access to your remote system and if you have configured thedeploy
command properly, the whole repo except for thenode_modules
directory will be copied to the remote system - Commit the changes to the
package.json
file to git
The following instructions and commands are done on the remote system:
ssh
to the remote system and navigate to the target directory- Install the projects dependencies, by running either
npm install
or justyarn
. - To view the production build in action on the remote server, run the command
start-server
. Use your browser to navigate to the server's IP address/url and port 8000, (for examplehttp://123.123.123.123:8000
orhttp://mydemosite.org:8000
) - Check out that the app works as expected
- Exit out of the
start-server
command - Run the
start-remote-server
command. This will run the server as a background process, no longer connected to yourssh
session (so you can log out of the remote system without killing the server process). Hit enter until you get the command prompt - Do a hard reload of the app with your browser to verify that it still loads
- Log out from the remote server
- Your app is now deployed!
When you have made changes to the app and want to deploy the updates to the remote server, repeat the Deployment steps