• Stars
    star
    215
  • Rank 183,925 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 7 years ago

Reviews

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

Repository Details

Simplified, fluent Webpack API with presets. Describe *what* your app needs, not *how*.

@terse/webpack

Join the chat at https://gitter.im/ericclemmons/terse-webpack

travis build version downloads MIT License

Webpack simplified in a fluent API with presets & an escape hatch so you're not locked in.


Why?

  • Webpack is powerful, but extremely complicated for newcomers to use.
  • Merging configuration objects is exceedingly difficult and error-prone.
  • Using Webpack on both the server & client is necessary once you leverage Webpack's APIs (e.g. require.context, require.ensure).
  • There are tons of configuration pitfalls that can negatively impact your build that you shouldn't have to know about.
  • It's a full-time job keeping up-to-date with the latest build optimizations.
  • Most React boilerplates have similar configuration, but no abstraction for composition.

Why Not?

  • You're comfortable with Webpack configuration.
  • You consider abstraction bad (e.g. "magic" or "indirection").
  • You have to get access to the "bare-metal" APIs.
  • TODO - Check Twitter for more cynical responses.

How?

This project attempts to solve these problems via:

  • Built on Webpack2, with the latest advancements.
  • Simple, fluent API that takes the guess-work out.
  • Escape hatch to copy/paste the generated, raw config.
  • Optional .presets for getting started quickly.
  • Functional reducers that you can override to customize the output.
  • Each action creates a new config, so you can easily compose them.

Upcoming features:

  • .presets:
    • .autoinstall() - Install missing dependencies.
    • .conventions() - Default input & output sources.
    • .hot() - Simplify HMR.
    • .offline() - Add offline support to your app.
    • .react() - Quickly get started with React.
  • terse-webpack CLI - Start coding without any initialization.
  • GUI - Get started on a new project with a few clicks.

Example

// webpack.config.js
module.exports = require("@terse/webpack").api()
  .entry("./src/client.js")
  .loader("babel", ".js", {
    exclude: /node_modules/,
    query: { cacheDirectory: true },
  })
  .modules("./lib")
  .output("build/client")
  .target("web")
  .when("development", function(api) {
    return api
      .entry({
        client: [
          "webpack-hot-middleware/client?reload=true&timeout=2000",
          "./src/client.js",
        ],
      })
      .plugin("npm-install-webpack-plugin")
      .plugin("webpack.HotModuleReplacementPlugin")
      .plugin("webpack.NoErrorsPlugin")
      .sourcemap("source-map")
    ;
  })
  .getConfig()
;
  1. Generates client.js in the build directory from ./src/client.js.
  2. Parses .js files (excluding node_modules) with Babel.
  3. Searches node_modules and ./lib for non-relative files.
  4. Outputs assets to ./build/client.
  5. Target platform is web (vs. node).
  6. When NODE_ENV is development: a. Override client.js to support HMR. b. Add npm-install-webpack-plugin to auto-install missing dependencies. c. Add HMR support. d. Enable source-map-style source maps (e.g. .map files).

Dependencies

I recommend using this against the latest Node + NPM v3.

Installation

npm install @terse/webpack

Usage

View the example.

Replace the contents of webpack.config.js (and others) with:

module.exports = require("@terse/webpack").api()
  ...
  .getConfig()
;

It's crucial to call .getConfig() to return the Webpack configuration.

With the upcoming .presets, it'll be as simple as:

module.exports = require("@terse.webpack").api()
  .presets("autoinstall", "hot", "react", "offline")
  .target("web")
  .getConfig()
;

API

  • .api([customFeatures[, customReducers]])

    Begins fluent interface, optionally accepted an array of custom features and custom reducers.

  • .alias(name[, pathOrName])

    Maps a package name (e.g. react) to another library (e.g. react-lite) or to a path (e.g. ./node_modules/react).

  • .context(path)

    Config files are relative to this folder. (Default: process.cwd())

  • .env(environment)

    Overrides NODE_ENV (defaults to development) the build is for.

  • .externals(...[Function, RegExp, String])

    Prevents Webpack from bundling matching resources.

  • .loader(name[, extensions = ".js"[, options]])

    Add a loader for the given extension(s) with the given settings.

  • .modules(path)

    Lookup non-relative (e.g. my-cool-lib) modules in this folder as well as node_modules.

  • .node(options)

    Override built-in Node constants & libs (e.g. __dirname, __filename)

  • .output(pathOrOptions)

    Set the output path, or specify the entire Webpack output configuration.

  • .plugin(name, ...args)

    Installed automatically with the given arguments.

  • .preLoader(name[, extensions = ".js"[, options]])

    Just like .loader, but is ran before all other loaders.

  • .sourcemap(type)

    Add a source map to the build.

  • .target(runtime)

    Either node or web.

  • .getConfig()

    Returns the Webpack configuration

    • .toString()

      Returns the Webpack configuration as a string.

  • .getState()

    Returns the normalized configuration (prior to reducing).

    • .toString()

      Returns a string of the normalized configuraiton.

License

MIT License 2016 © Eric Clemmons

More Repositories

1

click-to-component

Option+Click React components in your browser to instantly open the source in VS Code
TypeScript
1,710
star
2

react-resolver

Async rendering & data-fetching for universal React applications.
JavaScript
1,646
star
3

grunt-angular-templates

Grunt build task to concatenate & pre-load your AngularJS templates
JavaScript
712
star
4

webpack-hot-server-example

Webpack Hot Module Replacement (HMR) Example with Express
JavaScript
367
star
5

polydev

Faster, route-centric development for Node.js apps with built-in Hot Module Replacement.
JavaScript
284
star
6

unique-selector

Given a DOM node, return a unique CSS selector matching only that element
JavaScript
260
star
7

grunt-express-server

Grunt task for running an Express Server that works great with LiveReload + Watch/Regarde
JavaScript
248
star
8

start-server-webpack-plugin

Automatically start your server once Webpack's build completes.
JavaScript
158
star
9

grunt-react

[DEPRECATED] Grunt task for compiling Facebook React's .jsx templates into .js
JavaScript
151
star
10

per-env

Clean up your package.json with per-NODE_ENV npm scripts
JavaScript
133
star
11

genesis-skeleton

Modern, opinionated, full-stack starter kit for rapid, streamlined application development.
CoffeeScript
106
star
12

if-env

Simplify npm scripts with `if-env ... && npm run this || npm run that`
JavaScript
97
star
13

node-recorder

Simple recording & replaying of HTTP requests for predictable development & testing.
TypeScript
97
star
14

jinja.js

Twig/Jinja/JinJS Client-Side Templating + jQuery Plugin
JavaScript
76
star
15

mdx-site

Static site generator powered by TypeScript, MDX, & React.
TypeScript
51
star
16

next.js-conf-2020

From Front-end to Full Stack with Amplify Framework
JavaScript
38
star
17

reload-server-webpack-plugin

Webpack plugin that automatically (re)starts your server between builds.
JavaScript
38
star
18

bookshelf-manager

Easily wire up models to APIs with supported for complex, nested saving.
JavaScript
34
star
19

universal-webpack

Library to greatly simplify running, watching, testing, & deploying universal apps with webpack.
JavaScript
34
star
20

medium-to-markdown

Convert Medium URLs to Markdown
JavaScript
30
star
21

mvc-to-react

Eric Clemmons' Space City JS 2015 talk – "Moving from MVC to React"
JavaScript
30
star
22

angular-github-demo

AngularJS demo application for HoustonJS
CSS
26
star
23

tech-2016-lightning-talks

10-minute lightning talks about Storybook, Styled Components, MobX, & Jest.
JavaScript
26
star
24

react.lazy-example

Testing out React.lazy (https://github.com/facebook/react/pull/13398)
JavaScript
24
star
25

grunt-angular-modularize

Write AngularJS Modules Once. Build with RequireJS (AMD), Browserify (CommonJS), or simply concat.
JavaScript
23
star
26

hot-module

Reload changed files in Node *without* restarting the server (like nodemon/piping/etc.)
JavaScript
23
star
27

github-semantic-version

Automated semantic version releases powered by Github Issues.
JavaScript
21
star
28

ECVagrantBundle

Symfony2 bundle to generate a working PHP5.3+ Vagrant environment
PHP
21
star
29

codelift

Visual Development for React, Next.js, & Tailwind CSS
17
star
30

de-pagify

Bookmarklet to enable "endless scroll" on popular sites
PHP
16
star
31

performant-3rd-party-widgets

Houston.js demo + slides for babel/webpack/react bundling & optimizations.
JavaScript
15
star
32

diez

Incredibly simple, Dependency Injection for isomorphic Javascript applications.
JavaScript
14
star
33

jest-storybook

Generate Jest snapshots from existing storybooks (similar to storyshots).
JavaScript
13
star
34

react-tooling-challenge

Competition to improve the tooling landscape for all React users.
13
star
35

eslint-config-future

ESLint Shareable Config for ES5/ES6/ES7 Javascript
JavaScript
12
star
36

wordpress-skeleton

[DEPRECATED] Dude, use https://github.com/genesis/wordpress/ !!
PHP
12
star
37

react-router-server-location

A React Router Location for universal apps.
JavaScript
12
star
38

start-cluster

Start a Node cluster by simply running `start-cluster`
JavaScript
11
star
39

graphql-context-services

GraphQL example using Context & Services
JavaScript
11
star
40

graphql-demo

Introduction to GraphQL (http://www.meetup.com/NodejsHouston/events/229815892/)
JavaScript
11
star
41

create-preact-pwa

"yarn create"-friendly version of preact-cli
JavaScript
9
star
42

grunt-verbosity

Adjust verbosity for individual grunt tasks
JavaScript
8
star
43

mootools-namespace

Allows Classes to specify namespace ("My.Fx.Accordion") and extend "Moo.Fx.Accordion", similar to Dojo.provide/require
JavaScript
6
star
44

tech-screen-template

Opinionated (but customizable!) template for tech screen interviews
TypeScript
6
star
45

express-hot-middleware

Simple way to enable hot-reloading in your Express applications.
JavaScript
6
star
46

babel-plugin-react-pure-to-class

https://github.com/gaearon/babel-plugin-react-transform/issues/57#issuecomment-167652102
JavaScript
5
star
47

graphql-mock-object

Easily prototype UIs with dynamic GraphQL objects
JavaScript
5
star
48

amplify-visor

Amplify Visor is a prototype GUI that customers run locally that streamlines the Amplify app-building experience – configuring & deploying Amplify visually, automatically installing dependencies, and reducing developer friction.
JavaScript
5
star
49

sync-github-pivotal

Bi-directional syncing between Pivotal Tracker & GitHub Issues
TypeScript
4
star
50

generator-genesis

Yeoman Generator for Genesis Skeleton
JavaScript
4
star
51

redux-reconnect

Redux hooks for React Resolver & Server-Side Rendering via "reconnect(...)"
3
star
52

create-graphql-app

Add an Amplify Function to `create-react-app`.
JavaScript
3
star
53

begin-react-app

Begin app
JavaScript
2
star
54

react-zones-example

Can Zones magically simplify SSR? http://blog.kwintenp.com/how-the-hell-do-zones-really-work/
2
star
55

vagrant-php

Instantly setup & launch PHP5.x Vagrant machine
PHP
2
star
56

vagrant-shim

Transparently run commands through your Vagrant VM.
PHP
2
star
57

sublime-typescript

DEPRECATED - Use Microsoft's official plugin instead!
2
star
58

ericclemmons

MDX
2
star
59

ericclemmons.com

TypeScript
2
star
60

amplify-flow

Native app for GitHub issue management for Amplify JS
TypeScript
2
star
61

ericclemmons.github.io

Official (Dynamic) Website of Eric Clemmons
CSS
2
star
62

zend-memcached-namespaced

Zend_Cache_Backend_Memcached with Namspace support for clearing specific keys
1
star
63

react-shared-state

Simple <SharedState> component to wrap your app & auto-inject Redux & MobX stores.
1
star
64

angular-lazy-load

Experimenting with lazy-loading angular.modules
JavaScript
1
star
65

microbundle-monorepo

Having an issue with CSS not being extracted when part of a monorepo
CSS
1
star
66

flummox-parent-promise

JavaScript
1
star
67

css-system

JavaScript
1
star
68

genesis-skeleton.com

Official website of Genesis Skeleton
CoffeeScript
1
star
69

mobx-resolver

Prefect MobX data dependencies before rendering React components.
1
star
70

redux-devtools-visual

Easily scrub through a visual history of your application, branch, and repeat!
1
star
71

amplify-js-canary

Canary releases for https://github.com/aws-amplify/amplify-js
1
star
72

amplify-js-issues-4506

https://github.com/aws-amplify/amplify-js/issues/4506
HTML
1
star
73

capistrano-svn-deployment

Example deployment script using Python & Capistrano for PHP apps in SVN
Python
1
star
74

ng-gitboard

Github dashboard powered by Angular.
JavaScript
1
star
75

redux-server

Redux-powered server & middleware for predictably handling requests with immutable responses.
1
star
76

ericclemmons.github.com

Office (Static) Website of Eric Clemmons
1
star