Starbase is a Webpack 3, ES6 & PostCSS boilerplate that utilizes some of the juiciest open source tools around:
This boilerplate is intended to be small in scope so that it may be easily extended and customized, or used as a learning tool for folks who are trying to become familiar with Webpack 3.
Starbase is completely free, open source and public domain, so you are free to do whatever you wish with it -- commercially or personally. You can buy me a beer next time you're in Boston, star the project and tell a friend, or you can erase all signs of origin and tell your coworkers that you made it yourself. It's all good!
After completing the steps below, you will be ready to begin using Starbase:
- Install Node.js (latest LTS recommended)
- Install Yarn
- Clone Starbase into your project root directory
- Install dependencies by running
yarn
in your project root directory
Note: if you hate Yarn for some reason, you can skip Step 2 and use npm install
instead of yarn
in Step 4.
Starbase uses webpack-dev-server to serve up your project at http://localhost:8080 for streamlined and convenient development.
After running npm run watch
in the project root, your /src
code will be served at the url above and watched for changes. As you modify code in /src
, the project will be recompiled and your browser will refresh to show the latest changes.
cd /path/to/starbase
npm run watch
Use npm run build
in your project root to run a production build.
Production builds compile & minify your assets into /dist
for distribution and/or integration into whatever codebase you'll be using these assets in.
cd /path/to/starbase
npm run build
Starbase is setup to clear all contents of /dist
(where compiled assets are piped into) during each npm run build
. If you'd like to remove this part of the build process, perform the following steps:
- remove
CleanWebpackPlugin
from the plugins array in/webpack/webpack.config.prod.js
- remove
CleanWebpackPlugin
as a requirement at the top of/webpack/webpack.config.prod.js
- remove the
CleanWebpackPlugin
dependency from/package.json
Removing the cleanup process means that deleted assets in /src
will not be deleted in /dist
until you manually do so. I recommend keeping the cleanup process intact unless you have a specific reason not to, such as having un-managed assets in /dist
.
Because Starbase was built to accommodate ES6 & CommonJS (and not JQuery) it is assumed that you'll be using fetch for asynchronous requests.
Fetch is supported in all modern browsers, but some old dogs still don't support it and that's what we need the es6-promise & whatwg-fetch polyfills for.
If you want to remove these for any reason, perform the following steps:
- run
yarn remove es6-promise whatwg-fetch
in the project root to remove the dependencies - remove the first few lines of
/src/bundle.js
(it'll be obvious which ones)
Note: if you think you might use fetch in the future, comment-out the includes instead of deleting them. Commented-out code is stripped out in production builds.
Starbase uses ESLint for Javascript (ES6) linting and stylelint for CSS linting. The configs (/.eslintrc
and /.stylelintrc
respectively) included out of the box contain some basic common rules. Modify them to your liking to encourage consistent code throughout your project.
Starbase enforces the Airbnb JavaScript Style Guide with ESLint via eslint-config-airbnb. These rules are basically the industry standard in 2017 so I'd recommend adhering to them, but you can override individual rules via the project /.eslintrc
file. I've included a couple basic overrides (in /.eslintrc
) to demonstrate usage.
- in
/.eslintrc
, remove the line that saysextends
- in
/package.json
, remove theeslint-config-airbnb
dependency - run
yarn
(ornpm update
if you hate yarn)
After completing the steps above, the only rules that eslint will enforce are the ones you define in the rules
object in /.eslintrc
.
Starbase supports global CSS variables via the :root pseudo-element, which can be found in /src/variables/variables.css
. You can split your variables into multiple files, and just import them into /src/variables/variables.css
if you'd like them to be more granular.
These variables automatically injected into any CSS in the /src/components
and /src/app
directories, so they are always available for use in your app & component stylesheets.
Each component that comes with Starbase uses at least one variable to demonstrate the functionality.
All variables are cleaned up in your production code and only the values will remain, so there is no bloat or downside to using these variables. Go nuts!