@iovx/iv-tool

1.1.5 • Public • Published

iv-tool

npm

node deps tests builds builds2 coverage licenses PR's welcome

基础打包工具

  • 支持 typescript 工具库打包

配置

优先级 iv.config.js > iv.json > .ivrc

module.exports = function() {
  return {
     "tsFiles": "demo/**/*.ts",
      "dist": "./",
      "cwd": "demo",
      "compress": {
        "dist": false
      },
      "clean": [
        "demo/dist/es",
        "demo/dist/lib"
      ]
  }
}

cli

// 打包产出 dist | es | dist
iv build 
// 开启监控模式,实时打包
iv start 
// 启动开发服务器
iv server 
// 生成项目打包文件
iv build:page 

详细

/**
 * @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',
    },
  };
};

Package Sidebar

Install

npm i @iovx/iv-tool

Weekly Downloads

1

Version

1.1.5

License

MIT

Unpacked Size

68.2 kB

Total Files

79

Last publish

Collaborators

  • ixw2017