Giter Site home page Giter Site logo

roadhog's Introduction

roadhog

NPM version Build Status NPM downloads Dependencies

查看中文版

Roadhog is a cli tool with devbuild 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

roadhog's People

Contributors

afc163 avatar alex1990 avatar arvinxx avatar bubkoo avatar chenkan avatar codering avatar d19900819 avatar dickeylth avatar heziqiang avatar ibigbug avatar ikobe avatar iwege avatar jdz321 avatar lishengzxc avatar maxiaochuan avatar paranoidjk avatar plainnany avatar popomore avatar pvtyuan avatar sandwich99 avatar sorrycc avatar timyi avatar tsury avatar valleykid avatar warmhug avatar whatwewant avatar xlsdg avatar yamakasiluke avatar yesmeck avatar zhangjx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

roadhog's Issues

.roadhogrc配置信息格式太严格了

{
    "disableCSSModules": true,
    "autoprefixer": {
        "browsers": [
            "last 4 versions", 
            "Firefox ESR", 
            "> 1%", 
            "ie >= 8", 
            "iOS >= 8",
            "Android >= 4"
       ]
    },
    aa: "a"
}

必须完全是json标准格式,key必须要用双引号包裹,value如果是有字符串类型也必须用双引号包裹。

postcss-pxtorem 不能处理antd-mobile css

未采用roadhog时使用:

webpackConfig.postcss.push(pxtorem({
    rootValue: 100,
    propWhiteList: [],
  }));

能够正确处理antd-mobile和自己css文件中的单位
现在使用roadhog无法处理antd-mobile,但能够处理自己的css文件:

let postcss = webpackConfig.postcss();

  postcss.push(pxtorem({
    rootValue: 100,
    propWhiteList: [],
  }));

  webpackConfig.postcss = function () {
    return postcss;
  };

在开发环境设置 <img src="img/logo.png"> 找不到

在开发环境下,引用图片
<div className='header__container--left'> <img src="img/logo.png" /> <div className='header__text'> {title} </div>

打开浏览器,图片无法显示,而且开发者工具里面显示的是
image

type 不是 png 而是 text\html 请问大大怎么解决这个问题。
使用 roadhog 时静态资源需要放在什么特殊的地方吗? 附上我的配置文件和项目结构如下
image

image

启动报错

@ start /Users/MacHewleet/Workspace/SAW_S/testtest

roadhog server

/Users/MacHewleet/Workspace/SAW_S/testtest/node_modules/roadhog/bin/roadhog.js:9
const [major, minor] = nodeVersion.split('.');
^

SyntaxError: Unexpected token [
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:430:10)
at startup (node.js:141:

貌似less无效果?

.roadhogrc

{
    "disableCSSModules": true,
    "less": true,
    "autoprefixer": {
        "browsers": [
            "last 4 versions",
            "Firefox ESR",
            "> 1%",
            "ie >= 8",
            "iOS >= 8",
            "Android >= 4"
        ]
    }
}

index.less

.box {
    background: red;
}

index.js

import './index.html'
import './index.less'

import React, {Component} from 'react'
import ReactDOM from 'react-dom'

class App extends Component {

    componentDidMount() {
     
    }
    
    render() {
        return (
                <div className="box">
                    测试
                </div>
        )
    }
} 

 ReactDOM.render( <App />, document.getElementById('root'))

新建了一个测试文件 ./test/users-test.js

新建了一个测试文件
./test/users-test.js
代码如下

import expect from 'expect';
import users from '../src/models/users';

describe('reducers', () => {

  describe('reducer', () => {
    it('it should save', () => {
      expect(users.reducers['save']({}, { payload: { data:[],total:1,page:1 }})).toEqual({list:[],total:1,page:1});
    });
  })
});

出现如下错误, 请问babel-polyfill 要如何配置
$ roadhog test
/private/tmp/dva-example-user-dashboard/src/utils/request.js:34
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(url, options) {

如何使用postcss-pxtorem

用之前的方案是可以设置:
webpackConfig.postcss.push(pxtorem({
rootValue: 100,
propWhiteList: [],
}));
现在用roadhog怎么配置?

roadhog lint

需考虑 Intellij IDEA 编辑器的支持。

支持 webpack.config.js 的编程配置,但不推荐

⚠️⚠️⚠️ 使用这种配置方式将不能保证 roadhog 之后的无缝升级,比如切换到 webpack2,rollup 或者其他,比如内部配置变更也可能导致失效。

所以会在支持的同时给予 WARN 警告。

能不能可以指定一些目录下的文件都走babel编译。

我将一些项目的通用代码抽出来,用npm pack打包成本地包,由于代码都是jsx+es6的,现在都是pack前用babel编译,这样其它项目使用的时候看到的是es5的代码。如果不用 babel编译后打包,会提示"SyntaxError: Unexpected token"的错误。

能不能类似src,我们指定其它几个node-modules目录下的js也需要babel编译?

整合antd-mobile 出错

{
  "entry": "src/index.js",
  "disableCSSModules": false,
  "autoprefixer": null,
  "proxy": null,
  "extraBabelPlugins": [
    "transform-runtime",
    ["import", { "libraryName": "antd-mobile", "style": true }]
  ],
  "env": {
    "development": {
      "extraBabelPlugins": [
        "dva-hmr"
      ]
    }
  }
}

error:

Error in ./src/index.js
Module build failed: ReferenceError: Unknown plugin "import" specified in "base" at 2, attempted to resolve relative to "/Users/macpro/develop/jaway/smartdrive/track/src"
    at Array.map (native)
 @ multi index

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.