• Stars
    star
    2,719
  • Rank 16,756 (Top 0.4 %)
  • Language
    JavaScript
  • Created almost 8 years ago
  • Updated over 5 years ago

Reviews

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

Repository Details

๐Ÿท Cli tool for creating react apps, configurable version of create-react-app.

roadhog

NPM version Build Status NPM downloads Dependencies

ๆŸฅ็œ‹ไธญๆ–‡็‰ˆ

Roadhog is a cli tool with devใ€build and test commands. It's based on react-dev-utils and is consistent with the experience of create-react-app. You can imagine this is a configurable version of create-react-app.

Docs

Features

  • ๐Ÿ“ฆ out of the box React application development tools, built-in css-modules, babel, postcss, HMR, etc.
  • ๐Ÿ  create-react-app experience
  • ๐Ÿšจ webpack configuration in JSON format
  • ๐Ÿ”ฅ mock
  • โœ‚๏ธ test based on jest, ui test with enzyme

Getting started

## Install globally or locally
$ npm i roadhog -g

## Check version
$ roadhog -v
2.0.0

## Local development
$ roadhog dev

## Build
$ roadhog build
$ NO_COMPRESS=1 roadhog build

## Test
$ roadhog test

Mock

roadhog dev support mock, configured in .roadhogrc.mock.js.

e.g.

export default {
  // Support type as Object and Array
  'GET /api/users': { users: [1,2] },

  // Method like GET or POST can be omitted
  '/api/users/1': { id: 1 },

  // Support for custom functions, the API is the same as express@4
  'POST /api/users/create': (req, res) => { res.end('OK'); },
};

Use the public directory

Files in the public directory would be copied to the output directory (by default ./dist) on the dev and build. So favicon, iconfont, html, html quoted pictures could be stored here.

Configuration

roadhog's webpack part is based on the af-webpack's implementation. For configuration, create .webpackrc in the project root. The format is JSON, e.g.

{
  "externals": { "react": "window.React" }
}

If you prefer JS configuration, or need to do some programming or abstract judgment, you can use .webpackrc.js configuration file, support ES6 syntax, e.g.

export default {
  externals: { react: 'window.React' },
}

Index:

entry

Specify webpack entries, support glob format.

suppose your project is multipages, wanting files in src/pages as entries. you can do the followings.

"entry": "src/pages/*.js"

theme

Configure the theme, in fact, with less variables. Support both object and string type, the string needs to point to a file which return configurations.

e.g.

"theme": {
  "@primary-color": "#1DA57A"
}

or,

"theme": "./theme-config.js"

define

Pass to code through the webpack's DefinePlugin plugin, the value will automatically be processed with JSON.stringify.

e.g.

"define": {
  "process.env.TEST": 1,
  "USE_COMMA": 2,
}

externals

Configure webpack's [externals] (https://webpack.js.org/configuration/externals/) property.

e.g.

// Don't pack react and react-dom
"externals": {
  "react": "window.React",
  "react-dom": "window.ReactDOM"
}

alias

Configure webpack's resolve.alias property.

extraResolveExtensions

Configure webpack's resolve.extensions property.

browserslist

Configure browserslist, works on both babel-preset-env and autoprefixer.

e.g.

"browserslist": [
  "> 1%",
  "last 2 versions"
]

publicPath

Configure webpack's output.publicPath property.

outputPath

Configure webpack'sย output.pathย property.

devtool

Configure webpack's devtool property.

commons

Configure webpack's CommonsChunkPlugin plugin, the format is Array.

e.g.

"commons": [
  {
    async: '__common',
    children: true,
    minChunks(module, count) {
      if (pageCount <= 2) {
        return count >= pageCount;
      }
      return count >= pageCount * 0.5;
    },
  },
]

hash

Configuration to build with hash file name, and it's usually used in conjunction with the manifest.

html

Configure html-webpack-plugin plugin.

e.g.

"html": {
  "template": "./src/index.ejs"
}

disableCSSModules

Disableย CSS Modules๏ผŒwe do not recommend doing this.

disableCSSSourceMap

Disable generate CSS's SourceMap.

extraBabelPresets

Define an additional list of babel presets, the formatt is Array.

extraBabelPlugins

Define an additional list of babel plugins, the formatt is Array.

extraBabelIncludes

Define an additional list of file matches that need to be transformed with babel, the format is Array.

copy

Define a list of files that need to be copied. The format is an array, and the format of the item refers to the configuration of [copy-webpack-plugin] (https://github.com/webpack-contrib/copy-webpack-plugin).

e.g.

"copy": [
  {
    "from": "",
    "to": ""
  }
]

proxy

Configure the [proxy] (https://webpack.js.org/configuration/dev-server/#devserver-proxy) property of webpack-dev-server.

e.g. proxy requests to other servers,

"proxy": {
  "/api": {
    "target": "http://jsonplaceholder.typicode.com/",
    "changeOrigin": true,
    "pathRewrite": { "^/api" : "" }
  }
}

Then visit / api / users to access the data from [http://jsonplaceholder.typicode.com/users](http://jsonplaceholder.typicode.com/users].

sass

Configure the options for [node-sass] (https://github.com/sass/node-sass#options). Note: node-sass and sass-loader dependencies must be installed in the project directory when using sass.

manifest

Configure to generate manifest.json, it's option will pass to https://www.npmjs.com/package/webpack-manifest-plugin.

e.g.

"manifest": {
  "basePath": "/app/"
}

ignoreMomentLocale

Ignore moment locale file, used to reduce the size.

disableDynamicImport

Disable import () to load on demand, but bundle all the files in a single file, implement via babel-plugin-dynamic-import-node-sync.

env

Set specific options for certain environment. development is for dev, and production is for build.

e.g.

"extraBabelPlugins": ["transform-runtime"],
"env": {
  "development": {
    "extraBabelPlugins": ["dva-hmr"]
  }
}

Thus, extraBabelPlugins in development is ['transform-runtime', 'dva-hmr'], and ['transform-runtime'] in production.

Environment Variables

You can temporarily configure some parameters for environment variables, including:

  • PORT, default 8000
  • HOST, default localhost
  • ANALYZE, whether to analyze the output bundle in roadhog build
  • ESLINT, set none disable eslint check
  • TSLINT, set none disable tslint check
  • COMPRESS, set none to disable file compressing in roadhog build
  • BROWSER, set none to disable browser open in roadhog dev

e.g. start dev server with port 3000,

# OS X, Linux
$ PORT=3000 roadhog dev

# Windows (cmd.exe)
$ set PORT=3000&&roadhog dev

# Or use cross-env for all platforms
$ cross-env PORT=3000 roadhog dev

FAQ

Why is it called roadhog ?

roadhog is a hero from overwatch, just like dva.

LICENSE

MIT

More Repositories

1

awesome-javascript

๐Ÿข A collection of awesome browser-side JavaScript libraries, resources and shiny things.
31,906
star
2

blog

๐Ÿ’ก
4,501
star
3

awesome-f2e-libs

๐ŸŽ‰ ๆ•ด็†ๆˆ‘ๅนณๆ—ถๅ…ณๆณจ็š„ๅ‰็ซฏๅบ“ใ€‚
1,546
star
4

weekly

MDH Weekly ๅ‰็ซฏๅ‘จๅˆŠ๏ผŒๆฏๅ‘จไธ€ไธŠๅˆ 9 ็‚นๅ‘ๅธƒใ€‚
TypeScript
1,063
star
5

awesome-tools

Awesome tools I used.
703
star
6

zaobao

570
star
7

f2e-decision-tree

343
star
8

esbuild-webpack-plugin

Use esbuild as minifier for webpack.
TypeScript
264
star
9

dva-boilerplate-electron

Yet another boilerplate for dva.
JavaScript
200
star
10

toy-vite

TypeScript
122
star
11

dva-example-react-native

ReactNative example for dva.
Objective-C
94
star
12

dva-boilerplate-typescript

Dva boilerplate for typescript.
TypeScript
83
star
13

example-webpack-mfsu

Start the antd + framer-motion project without cache in one second.
TypeScript
83
star
14

dva-boilerplate-isomorphic

Dva boilerplate for isomorphic.
JavaScript
74
star
15

es3ify-loader

ES3ify loader for webpack.
JavaScript
71
star
16

learn-react-with-umi

Learn react with umi by examples.
JavaScript
46
star
17

ae-html-to-react

ไธ€้”ฎ่ฝฌๆข AE ็ผ–่ฏ‘ๅ‡บ็š„ html ๅŠจ็”ปๆ–‡ไปถไธบ React ๆ ผๅผใ€‚
TypeScript
39
star
18

react-redux-boilerplate

A boilerplate with react, redux, redux-saga ...
JavaScript
39
star
19

gimi

TypeScript
36
star
20

sorrycc.com

https://sorrycc.com/
TypeScript
29
star
21

ruban

Ruban is a personal tool pack for creating repos.
JavaScript
23
star
22

import-helper

Don't waste time to write import/require statement.
JavaScript
22
star
23

frontend-interview-book-by-chatgpt

frontend-interview-book-by-chatgpt
21
star
24

alfred-douban

Alfred 3 workflow to find movie from douban.
JavaScript
20
star
25

test-federated-modules

JavaScript
19
star
26

url-system

TypeScript
17
star
27

keep-chatgpt-simple

keep-chatgpt-simple
JavaScript
14
star
28

dva-example-antd-mobile

dva example of antd-mobile.
JavaScript
13
star
29

docaid

TypeScript
12
star
30

sorrycc

11
star
31

sekiro

A framework based on umi. (demo only)
JavaScript
10
star
32

webp-support

Script to feature detect if browser support WebP.
JavaScript
10
star
33

wau

Watch and upload.
CoffeeScript
9
star
34

spm-handbook

How to build modular applications with spm.
9
star
35

toy-bundler

toy-bundler
TypeScript
7
star
36

simple-react-boilerplate

JavaScript
7
star
37

pc-mobile-example

TypeScript
7
star
38

chinese-convert-example

TypeScript
5
star
39

generator-spm

A SPM Project generator for Yeoman.
JavaScript
5
star
40

chatgpt-telegram-bot

TypeScript
5
star
41

css-resources

Find and replace all *image* and *font* resources in css.
JavaScript
5
star
42

module-analyze-examples

JavaScript
5
star
43

redux-bind

Higher Order Component for antd to keep ui state in a Redux store.
JavaScript
5
star
44

obsidian-sorrycc

TypeScript
4
star
45

gulp-jsbeautify

js-beautify plugin for gulp
JavaScript
4
star
46

baby

4
star
47

tpsmate-mac

4
star
48

toy-umi

JavaScript
4
star
49

umi-example-monaco-editor

TypeScript
4
star
50

cmdclean

A build tool that converts CMD code to standard JavaScript.
JavaScript
4
star
51

github-helper

Objective-C
4
star
52

magicclone

A magic clone cli for github.
JavaScript
4
star
53

umi-plugin-hello

umi plugin for tutorial.
JavaScript
4
star
54

create-sorrycc

Self-use boilerplates.
JavaScript
3
star
55

ctos

a tool to transform component package to spm@3x package
JavaScript
3
star
56

require-on-demand

Require package on demand.
JavaScript
3
star
57

schema2tsd

็ผ–่ฏ‘ Fengdie Schema ไธบ TypeScript ็ฑปๅž‹ๅฎšไน‰ๆ–‡ไปถใ€‚
JavaScript
3
star
58

cdeps

Get absolute dependences recursively by entry file, support js and css.
JavaScript
3
star
59

sinew-node

Sinew-Node collects structured data from web sites (screen scraping).
CoffeeScript
2
star
60

cpu-history

JavaScript
2
star
61

test-umi-4-lint

TypeScript
2
star
62

scripts-hook

JavaScript
2
star
63

node-webapp-template-with-coffee

CoffeeScript
2
star
64

electron-redux-boilerplate

Dead simple electron redux boilerplate based on ant-tool.
JavaScript
2
star
65

umi-plugin-sofa

JavaScript
2
star
66

test-gh-pages

JavaScript
2
star
67

hello-yarn-2

JavaScript
2
star
68

seajs-app-sample

JavaScript
2
star
69

test-next-live

TypeScript
2
star
70

feedback.umijs.org

2
star
71

atpl-loader

Webpack loader for anima-template.
Makefile
2
star
72

v3-umijs-org

HTML
2
star
73

umd-bundler

Umd bundler basedon webpack.
JavaScript
2
star
74

test-build-result

JavaScript
2
star
75

babel-core-resolve-enhance

Enhance resolve dirname addable for babel 6 core.
JavaScript
1
star
76

install-dependency

Install dependency with any npm clients.
JavaScript
1
star
77

koa-jsx

koa middleware for transforming jsx of react
JavaScript
1
star
78

images

1
star
79

koa-combo2

Koa middleware for assets combo.
JavaScript
1
star
80

npm-github

Open github url in browser by npm pkg name.
JavaScript
1
star
81

aralejs.index

Source code index for aralejs.
Ruby
1
star
82

gulp-atpl

Gulp plugin for anima-template.
JavaScript
1
star
83

roadhog-example-config-loader

HTML
1
star
84

stepanim

A JavaScript class to do frame animation, just as google logo dose.
JavaScript
1
star
85

test-mfsu-fast-refresh-cpu-100

TypeScript
1
star
86

jest.automockoff

jest.autoMockOff()
JavaScript
1
star
87

md-server

A markdown server for local docs.
CSS
1
star
88

umi-lib-namedExports-problem

JavaScript
1
star
89

markify

JavaScript
1
star
90

dva-tutorial

JavaScript
1
star
91

test-release

1
star
92

robot

A robot that get information automatically for you per week.
JavaScript
1
star
93

examples

JavaScript
1
star