GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — hey-cli/README_zh.md at master · heyui/hey-cli

Expand file tree

/

README_zh.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
223 lines (189 loc) · 4.95 KB
/

README_zh.md

Copy path

File metadata and controls

223 lines (189 loc) · 4.95 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

hey-cli

webpack脚手架,hot-dev-server,build。 不需要理解webpack,只需要知道如何配置就可以使用,摆脱繁琐重复的webpack配置。

特性

  • 一次全局安装,所有的开发项目都支持,不需要每个项目都安装配置webpack。
  • 支持ES6
  • 支持热替换
  • 支持反向代理
  • 默认支持vue2.0,支持react
  • 支持全局less变量定义
  • 构建UMD模式的代码。
  • 只需要配置hey.conf.js配置文件即可使用

安装

npm install -g hey-cli

配置

在项目根目录下添加hey.conf.js配置文件。

module.exports = {
	//端口号
  "port": 9002,
  "dist": 'dist', //生成文件的根目录
  "timestamp": false, //build生成的static文件夹是否添加时间戳
  "clean": true, //打包之前清空dist目录
  "react": true, //支持react项目
  "openBrowser": true, // 自动打开浏览器
  "stat": true, // 是否生成stat.json
	//webpack相关配置    
  "webpack": {
    "console": false, //打包压缩是否保留console,默认为false
    "sourceMap" : false, //打包的时候要不要保留sourceMap, 默认为false
    "compress": true / false, // 默认值取决于是开发还是打包,设置值会影响打包的时候是否压缩js代码
    //公开path
    "publicPath": "/", 

    "output": {
      //输出哪些文件,主要是html,默认会加载和html文件名一样的js文件为入口。支持定义公用包。
      "./*.html": {
        "entry":"./src/index.js", //默认加载js文件,并且html自动引用。如果没有配置,则自动加载与html文件名同样的js文件。
      }
    },

    //定义resolve,https://webpack.js.org/configuration/resolve/
    "alias": {
      components: './src/components/',
      // 你可以使用 import index from 'components/index'  => src/components/index
    },

    //定义全局变量, https://webpack.js.org/plugins/provide-plugin
    "global": {
      "Vue": "vue",
      "$": "jquery",
      "log": "./js/common/log",
      // use export default
      Utils: [path.resolve(__dirname, 'src/js/common/utils'), 'default'],
    },

    //定义反向代理服务器,https://webpack.js.org/configuration/dev-server/#devserver-proxy
    "devServer": {
      "proxy": {
        //设定/api开头的url向定义的接口请求
        "/api": {
          "target": "http://yoda:9000"
        }
      },
      historyApiFallback: true
    },
    //定义外部引用,https://webpack.js.org/configuration/externals/
    "externals":{

    },

    //定义全局less参数定义,可以在任意less中使用参数
    globalVars: './static/css/var.less',
  },

  //未做关联引用的文件在build的时候复制到打包的文件夹中
  "copy": [
    "./images/**/*",
    "./help/**/*",
    "./template/**/*"
  ]
};

扩展配置

可以在hey.conf.js中webpack配置项中扩张配置以下属性:

  • plugins
  • module
  • node
  • externals
  • devServer

具体使用,请参照webpack文档.

示例

加载vue,vue-router

"hey": {
  "port": 9008,
  "timestamp": true,
  "dist": "gen",
  "webpack": {
    "publicPath": "/",
    "output": {
      "./*.html": {
        "entry":"./src/app"
      }
    },
    "global": {
      "Vue": "vue"
    },
    "devServer": {
      "historyApiFallback":true
    }
  }
}

外部加载vue,vue-router

"hey": {
  "port": 9008,
  "timestamp": true,
  "dist": "gen",
  "webpack": {
    "publicPath": "/",
    "output": {
      "./*.html": {
        "entry":"src/app"
      }
    },
    "global": {
      "Vue": "vue"
    },
    "devServer": {
      "historyApiFallback":true
    },
    "externals": {
      "Vue": "window.Vue",
      "VueRouter": "window.VueRouter"
    }
  }
}

构建UMD模式的公用代码

主要用于构建一些的公用代码,简单配置即可使用。
由于是打包成UMD模式的公用包,请不要使用import模式。

module.exports = {
  dist: "build",
  webpack: {
    umd: {
      entry: "./src/index.js",
      library: "Validator",
      filename: 'validator.js', //build后将生成/build/validator.js
      libraryExport: 'default'
    },
    externals: {
      "manba": "manba"  //该依赖包将不会打包进源码中
    }
  }
};

执行

启动webpack服务器

hey dev
hey build
# 使用自定义的配置文件执行
hey build -f index.esm.js

执行分析

You can generate analyze.

hey dev -r
# or
hey dev --report

# after hey build
hey report
# or
hey report -p port -f dist/stat.json

analyze

生成模板

根据已有的模板生成项目

hey init <project-name>

现有模板

  • Simple: 基础的ES6项目
  • HeyUI: HeyUI项目
  • HeyUI: HeyAdmin项目
  • Vue: 基础的Vue项目
  • React: 基础的React项目
  • ElementUI: Element项目
  • iViewUI: iViewUI项目
  • ViewUI: ViewUI项目

具体项目请参考hey-cli-template。

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.