• Stars
    star
    4,470
  • Rank 9,556 (Top 0.2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐ŸŽ’ Backpack is a minimalistic build system for Node.js projects.

backpack

backpack-status npm version Discord

Backpack is minimalistic build system for Node.js. Inspired by Facebook's create-react-app, Zeit's Next.js, and Remy's Nodemon, Backpack lets you create modern Node.js apps and services with zero configuration. Backpack handles all the file-watching, live-reloading, transpiling, and bundling, so you don't have to. It comes with a few conventions defaults (like support for the latest JavaScript awesomeness (i.e. async/await, object rest spread, and class properties)), but everything can be customized to fit your project's needs. Best of all, you can easily add Backpack to your existing Node.js project with just a single dependency.

Backpack comes with the "battery-pack included":

  • Latest ES6 features (including module syntax, async/await, object rest spread)
  • SUPER friendly, human readable error messages
  • Live reload (on saves, add/delete file, etc.)
  • Zero-config, one dependency.

HOWEVER, you can configure Backpack to your project's needs by extending the underlying Webpack 4 configuration.

PLEASE READ: If you're thinking of using Backpack with React.js, you should use Razzle instead. It is a project purpose-built for SSR React with an almost identical API.

Table of Contents

How to use

Install it:

npm i backpack-core --save

and add a script to your package.json like this:

{
  "scripts": {
    "dev": "backpack"
  }
}

After that there are just a few conventions defaults:

  • src/index.js: the entry of your app.

...actually that's it.

You can then run your application in development mode:

npm run dev

Successful builds will show a console like this. Note: screenshot taken from running the basic example npm run dev

Custom configuration

For custom advanced behavior, you can create a backpack.config.js in the root of your project's directory (next to package.json).

// backpack.config.js
// IMPORTANT: This file is not going through babel transformation.
// You can however use the ES2015 features supported by your Node.js version.
module.exports = {
  /* config options here */
};

Customizing webpack config

Example

To extend webpack, you can define a function that extends its config via backpack.config.js.

// backpack.config.js
module.exports = {
  webpack: (config, options, webpack) => {
    // Perform customizations to config
    // Important: return the modified config
    return config;
  },
};

Customizing babel config

Example

To extend our usage of babel, you can define a .babelrc file at the root of your app. This file is optional.

If found, Backpack will consider it to be the source of truth. Thus it must define what Backpack needs as well, which is the backpack-core/babel preset.

This is designed so that you are not surprised by modifications we could make to the default babel configurations.

Here's an example .babelrc file:

{
  "presets": [
    "backpack-core/babel",
    "stage-0"
  ]
}

Note: This works exactly like Next.js does.

Building for Production

Add a npm script for the build step:

{
  "scripts": {
    "dev": "backpack",
    "build": "backpack build"
  }
}

Then run the build command and start your app

npm run build
node ./build/main.js

CLI Commands

backpack dev

Runs backpack in development mode.

Your code will reload if you make edits.
You will see the build errors in the console that look like this.

backpack dev

backpack build

Builds the app for production to the build folder.
It correctly bundles your production mode and optimizes the build for the best performance.

You can run your production application with the following command:

node ./build/main.js

Your application is ready to be deployed!

Note: Make sure to add the build directory to your .gitignore to keep compiled code out of your git repository

FAQ

Is this like Create-React-App or Next.js?

Yes and No.

Yes in that they will all make your life easier.

No in that it that Backpack is focused on server-only applications. You should use create-react-app or Next.js for your frontend and then build your backend with Backpack.

Can I use this with React to build a universal app?

Technically, yes. However, we strongly advise against it at the moment. Backpack handles file-watching and reloading in a way that will make things like webpack-hot-middleware annoying to work with.

What syntactic features are transpiled? How do I change them?

We track V8. Since V8 has wide support for ES6, we don't transpile it. Since V8 doesnโ€™t support async/await and class properties yet, we transpile those.

See this and this

Why is it called Backpack?

Backpack is focused on server-only applications. We've been using it for building out Node.js backends and microservices. Under the hood, Webpack and a few other tools make the magic happen. Hence Backend + Webpack = Backpack.

Inspiration

Authors

More Repositories

1

formik

Build forms in React, without the tears ๐Ÿ˜ญ
TypeScript
33,930
star
2

tsdx

Zero-config CLI for TypeScript package development
JavaScript
11,268
star
3

razzle

โœจ Create server-rendered universal JavaScript applications with no configuration
JavaScript
11,102
star
4

the-platform

Web. Components. ๐Ÿ˜‚
TypeScript
4,404
star
5

after.js

Next.js-like framework for server-rendered React apps built with React Router
TypeScript
4,129
star
6

react-fns

Browser API's turned into declarative React components and HoC's
TypeScript
3,731
star
7

awesome-react-render-props

Awesome list of React components with render props
1,367
star
8

cypress-image-snapshot

Catch visual regressions in Cypress
JavaScript
887
star
9

presspack

๐Ÿ’ป Wordpress like it's 2022 with Webpack and Docker
JavaScript
689
star
10

react-parcel-example

Minimum viable React app with Parcel Bundler
JavaScript
482
star
11

minimum-viable-saas

A multi-tier membership SaaS in less than 500 lines of code w/Stripe and Firebase
JavaScript
444
star
12

formik-persist

๐Ÿ’พ Persist and rehydrate a Formik form to localStorage
TypeScript
375
star
13

mutik

A tiny (495B) immutable state management library based on Immer
TypeScript
325
star
14

typescript

TypeScript coding guidelines & configs for Formik
JavaScript
283
star
15

react-conf-2018

React Conf 2018 Source Code for "Moving to Suspense" Demo
JavaScript
227
star
16

react-email-workflow

Newsletter design tool
JavaScript
175
star
17

tsdx-monorepo

A really good starting point for your next React x TypeScript monorepo
TypeScript
175
star
18

formik-effect

Declarative component for managing side-effects in Formik forms. 580 bytes
TypeScript
166
star
19

formover

Build forms that pop bottles ๐Ÿพwith Formik and React Popper
TypeScript
160
star
20

react-simple-infinite-scroll

A brutally simple react infinite scroll component
TypeScript
141
star
21

react-persist

๐Ÿ’พ Persist and rehydrate React state to localStorage.
JavaScript
124
star
22

nextra-blank-custom-theme

A forkable Next.js site w/ a blank custom Nextra theme (w/Tailwind)
JavaScript
117
star
23

hyperhue

๐ŸŒˆ A fun HyperTerm theme that responds to your Philips Hue lights
JavaScript
103
star
24

reason-react-native-web-example

Razzle + Reason-React + React-Native-Web. Damn that's a lot of R's.
Reason
100
star
25

disco.chat

Add real-time ephemeral chat to any webpage.
TypeScript
96
star
26

react-router-nextjs-like-data-fetching

Demonstrating React Router 4's SSR awesomeness
JavaScript
89
star
27

dotfiles

My setup
Shell
52
star
28

razzle-react-vue-elm-php-lol

๐Ÿ”ฅ Blazing fast Razzle app with React, Vue, PHP, and Elm + HMR
JavaScript
49
star
29

formik-alicante

Formik slides & demos from React Alicante
JavaScript
46
star
30

codemods

Collection of codemods for TypeScript and JavaScript codebases
JavaScript
43
star
31

react-suspense-playground

Stock Market News app w/ React Suspense
JavaScript
43
star
32

razzle-unrouted

Blazingly fast server-rendered MVC Webapps with Preact and Webpack
JavaScript
42
star
33

nextjs-langchain-example

Demo of using LangChain.js with Next.js and Vercel Edge Functions (to stream the response)
TypeScript
41
star
34

framer-electron-preview

Quickly run Framer prototypes within Electron.
JavaScript
35
star
35

country-fns

๐ŸŒ Useful country data for forms and stuff.
JavaScript
35
star
36

squeezy

1 kB React component for accessible accordions / collapse UI
TypeScript
30
star
37

TIL

๐Ÿ“–Trying to document some of my learnings
30
star
38

react-europe-2019

Slides and demo app from my keynote
JavaScript
29
star
39

jpjs

Some TypeScript utils
TypeScript
21
star
40

emotion-jsxstyle

jsxstyle primitives powered by emotion
JavaScript
20
star
41

react-router-suspense-demo

React Suspense x React Router Exploration
JavaScript
17
star
42

nextjs-route-handler-email

Experimenting with react.email and Next.js 13 Route Handlers
TypeScript
16
star
43

react-snippets

My React snippets for JavaScript and TypeScript
13
star
44

jaredpalmer.github.io

TypeScript
12
star
45

framer-router

A little routing solution for Framer.js
CoffeeScript
11
star
46

thinkaboutthis.fm

Source code for thinkaboutthis.fm
TypeScript
11
star
47

formik-bloomberg-talk

Slides and examples from my talk at Bloomberg on October 31, 2019
JavaScript
10
star
48

jaredpalmer-vscode-extensionpack

All of my VS Code extensions .... in one extension pack
9
star
49

electron-starter

A minimal Electron starter
JavaScript
8
star
50

babel-preset-react-ts

Create React App's Babel 7 Preset, plus TypeScript
JavaScript
7
star
51

noirny

Website for Noir New York (formerly the lately). Opening 11/21/19
TypeScript
7
star
52

jest-jsxstyle

๐Ÿƒ Jest utilities for JSXStyle
JavaScript
6
star
53

flask-vercel

Python
6
star
54

jaredpalmer

it me.
5
star
55

saas-subdomain-nginx-node-docker

Example setup of SaaS-like user subdomains using Express, NGINX, and Docker Compose
JavaScript
5
star
56

juice.now.sh

Automattic's Juice CSS inliner as a microservice
HTML
4
star
57

datocms-next-js-blog-demo-9687

JavaScript
4
star
58

react-error-overlay-razzle-bug

JavaScript
3
star
59

glamor-jsxstyle

Future home of glamor-jsxstyle
JavaScript
3
star
60

reactnyc-formik

๐Ÿ“ˆ Formik presentation at the August React NYC meetup @Spotify
JavaScript
3
star
61

bf-solid-addons

Helpful addons to Buzzfeed's Solid CSS Framework
CSS
2
star
62

codesandbox-template-next.js

Next.js template for CodeSandbox Projects
TypeScript
2
star
63

framer-electron

Prototype desktop apps with Framer.js and Electron with your own editor.
JavaScript
2
star
64

formik-docs

WIP. Formik docs website
TypeScript
2
star
65

oss-deck

JavaScript
1
star
66

downshift-razzle-bug

JavaScript
1
star
67

next-back-button-error

JavaScript
1
star
68

flask-pipenv-example

Python
1
star
69

os-today

A list a of the GitHub repos you should be using.
JavaScript
1
star
70

blocks

TypeScript
1
star
71

ci-info

Go
1
star
72

hyperneon

Hyperterm theme that rotates neon colors
JavaScript
1
star