npm package: @iovx/iv-tool
Description: 微风平台基本打包工具库, 用于支持cli开发
Author: ibreeze2017
Latest version: 1.1.5

# iv-tool

[![npm][npm]][npm-url]

[![node][node]][node-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![builds][builds]][builds-url]
[![builds2][builds2]][builds2-url]
[![coverage][cover]][cover-url]
[![licenses][licenses]][licenses-url]
[![PR's welcome][prs]][prs-url]

基础打包工具

- 支持 typescript 工具库打包



## 配置

优先级
iv.config.js > iv.json > .ivrc

```js

module.exports = function() {
  return {
     "tsFiles": "demo/**/*.ts",
      "dist": "./",
      "cwd": "demo",
      "compress": {
        "dist": false
      },
      "clean": [
        "demo/dist/es",
        "demo/dist/lib"
      ]
  }
}

```

## cli

```bat
// 打包产出 dist | es | dist
iv build 
```

```bat
// 开启监控模式，实时打包
iv start 
```

```bat
// 启动开发服务器
iv server 

```
```bat
// 生成项目打包文件
iv build:page 
```


### 详细

```js

/**
 * @typedef {{
 *   log(...args),
 *   warn(...args),
 *   info(...args),
 *   success(...args),
 *   error(...args),
 * }} Log
 * @typedef {{script:string, env:{NODE_ENV:string},log:Log, args:string[]}} IVOptions
 */
/**
 * @param {IVOptions} options
 * @return {{cwd: string, pageOptions: {root: string, inject: {cdnUrl: string, apiUrl: string, baseUrl: string, core: {router: string}, nav: {home: string, member: string, console: string, passport: string, explore: string, docs: string, poster: string}, domain: string, loginUrl: string, callback: string}, page: {name: string, title: string, filename: string}, useDll: boolean, dll: {name: string, entry: string[]}[], server: {port: number, proxy: {"/local": {target: string, pathRewrite: {"^/local": string}}}}}, deployOptions: {url: string}}}
 */
module.exports = (options) => {
  const { script, log, env } = options;
  const flag = env.NODE_ENV === 'production';
  const isDevMode = script === 'start';
  log.info('当前模式:', isDevMode ? '开发模式' : '生产模式');
  return {
    cwd: '.',
    pageOptions: {
      root: '.',
      inject: {
        cdnUrl: flag ? 'https://static.example.io/cdn' : '/local',
        apiUrl: flag ? 'https://api.example.io/api' : '//api.assure.com/api',
        baseUrl: flag ? 'https://api.example.io' : '//api.assure.com',
        core: {
          router: 'browser',
        },
        nav: {
          home: flag ? '//www.example.io/' : isDevMode ? '//member.assure.com' : '//member.assure.com',
          member: flag ? '//i.example.io/' : isDevMode ? '//member.assure.com' : '//member.assure.com',
          console: flag ? '//console.example.io/' : isDevMode ? '//console.assure.com' : '//console.assure.com',
          passport: flag ? '//passport.example.io/' : isDevMode ? '//passport.assure.com' : '//passport.assure.com',
          explore: flag ? '//explore.example.io/' : isDevMode ? '//explore.assure.com' : '//explore.assure.com',
          docs: flag ? '//docs.example.io/' : isDevMode ? '//docs.assure.com' : '//docs.assure.com',
          poster: flag ? '//wiki.example.io/' : '//i.assure.io/',
        },
        domain: flag ? 'example.io' : 'assure.com',
        loginUrl: flag ? 'https://passport.example.io/' : isDevMode ? '//passport.assure.com' : '//passport.assure.com',
        callback: flag ? 'http://www.example.io/' : 'http://www.assure.com/',
      },
      page: {
        name: 'index',
        title: '微风文件管理中心',
        filename: 'index.html',
      },
      useDll: true,
      dll: [
        {
          name: 'bundle',
          entry: ['react', 'react-dom', 'react-router', 'react-redux', 'redux-saga', 'react-router-dom', 'axios'],
        },
      ],
      server: {
        port: 7227,
        proxy: {
          '/local': {
            target: 'http://127.0.0.1:8028/static/cdn',
            pathRewrite: { '^/local': '' },
          },
        },
      },
    },
    // const apiUrl = 'http://open.ixvz.io/api/file/upload';
    deployOptions: {
      url: 'http://open.ixvz.io/api/file/upload',
    },
  };
};


```


[npm]: https://img.shields.io/npm/v/webpack.svg
[npm-url]: https://npmjs.com/package/webpack
[node]: https://img.shields.io/node/v/webpack.svg
[node-url]: https://nodejs.org
[deps]: https://img.shields.io/david/webpack/webpack.svg
[deps-url]: https://david-dm.org/webpack/webpack
[tests]: https://img.shields.io/travis/webpack/webpack/master.svg
[tests-url]: https://travis-ci.org/webpack/webpack
[prs]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
[prs-url]: https://webpack.js.org/contribute/
[builds-url]: https://ci.appveyor.com/project/sokra/webpack/branch/master
[builds]: https://ci.appveyor.com/api/projects/status/github/webpack/webpack?svg=true
[builds2]: https://dev.azure.com/webpack/webpack/_apis/build/status/webpack.webpack
[builds2-url]: https://dev.azure.com/webpack/webpack/_build/latest?definitionId=3
[licenses-url]: https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack?ref=badge_shield
[licenses]: https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack.svg?type=shield
[cover]: https://img.shields.io/coveralls/webpack/webpack.svg
[cover-url]: https://coveralls.io/r/webpack/webpack/