# brain-cli

> A command line tool used to run projects

Latest version **3.0.0-alpha.15** (published 2026-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install brain-cli
pnpm add brain-cli
yarn add brain-cli
bun add brain-cli
```

Provides the command `brain-cli`.

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.0.0-alpha.15 |
| Published | 2026-09-04 |
| First published | 2021-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 50 |
| Unpacked size | 197.3 KB |
| Known vulnerabilities | 0 (+8 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | duanguang She |
| Maintainers | duanguang |
| Keywords | brain, cli, webpack-cli, brain-cli, react-cli, react-webpack |

## Links

- npm: https://www.npmjs.com/package/brain-cli
- Repository: https://github.com/duanguang/brain-cli
- Issues: https://github.com/duanguang/brain-cli/issues
- npm.io page: https://npm.io/package/brain-cli

## Dependencies (50)

- [glob](https://npm.io/package/glob.md) ^7.1.1
- [less](https://npm.io/package/less.md) ^4.2.0
- [open](https://npm.io/package/open.md) 0.0.5
- [core-js](https://npm.io/package/core-js.md) 3
- [postcss](https://npm.io/package/postcss.md) ^8.4.0
- [webpack](https://npm.io/package/webpack.md) ^5.90.0
- [commander](https://npm.io/package/commander.md) ^2.11.0
- [invariant](https://npm.io/package/invariant.md) ^2.2.2
- [ts-loader](https://npm.io/package/ts-loader.md) ^9.5.0
- [css-loader](https://npm.io/package/css-loader.md) ^6.10.0
- [typescript](https://npm.io/package/typescript.md) ^4.3.2
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.24.0
- [deep-assign](https://npm.io/package/deep-assign.md) ^2.0.0
- [less-loader](https://npm.io/package/less-loader.md) ^12.2.0
- [object-hash](https://npm.io/package/object-hash.md) ^1.1.5
- [webpack-cli](https://npm.io/package/webpack-cli.md) ^5.1.0
- [@rspack/core](https://npm.io/package/@rspack/core.md) ^2.2.1
- [autoprefixer](https://npm.io/package/autoprefixer.md) ^10.4.0
- [babel-loader](https://npm.io/package/babel-loader.md) ^9.1.0
- [style-loader](https://npm.io/package/style-loader.md) ^3.3.0
- [html-minifier](https://npm.io/package/html-minifier.md) ^3.4.0
- [react-refresh](https://npm.io/package/react-refresh.md) 0.14.2
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.24.0
- [postcss-loader](https://npm.io/package/postcss-loader.md) ^8.1.0
- [update-notifier](https://npm.io/package/update-notifier.md) ^4.1.1
- [react-hot-loader](https://npm.io/package/react-hot-loader.md) ^4.12.10
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.24.0
- [@rspack/dev-server](https://npm.io/package/@rspack/dev-server.md) ^2.2.1
- [resolve-url-loader](https://npm.io/package/resolve-url-loader.md) ^2.0.2
- [webpack-dev-server](https://npm.io/package/webpack-dev-server.md) ^4.15.2
- [@babel/preset-react](https://npm.io/package/@babel/preset-react.md) ^7.23.0
- [babel-plugin-import](https://npm.io/package/babel-plugin-import.md) ^1.13.0
- [copy-webpack-plugin](https://npm.io/package/copy-webpack-plugin.md) ^11.0.0
- [html-webpack-plugin](https://npm.io/package/html-webpack-plugin.md) ^5.6.0
- [webpack-spritesmith](https://npm.io/package/webpack-spritesmith.md) ^1.1.0
- [html-webpack-template](https://npm.io/package/html-webpack-template.md) ^6.0.1
- [postcss-plugin-px2rem](https://npm.io/package/postcss-plugin-px2rem.md) ^0.8.1
- [terser-webpack-plugin](https://npm.io/package/terser-webpack-plugin.md) ^5.3.0
- [babel-plugin-legion-hmr](https://npm.io/package/babel-plugin-legion-hmr.md) ^0.0.15
- [mini-css-extract-plugin](https://npm.io/package/mini-css-extract-plugin.md) ^2.8.0
- [webpack-bundle-analyzer](https://npm.io/package/webpack-bundle-analyzer.md) ^4.10.0
- [progress-bar-webpack-plugin](https://npm.io/package/progress-bar-webpack-plugin.md) ^1.12.1
- [@rspack/plugin-react-refresh](https://npm.io/package/@rspack/plugin-react-refresh.md) 2.0.2
- [css-minimizer-webpack-plugin](https://npm.io/package/css-minimizer-webpack-plugin.md) ^6.0.0
- [html-webpack-harddisk-plugin](https://npm.io/package/html-webpack-harddisk-plugin.md) ^0.1.0
- [add-asset-html-webpack-plugin](https://npm.io/package/add-asset-html-webpack-plugin.md) ^6.0.0
- [webpack-filter-warnings-plugin](https://npm.io/package/webpack-filter-warnings-plugin.md) ^1.2.1
- [@babel/plugin-transform-runtime](https://npm.io/package/@babel/plugin-transform-runtime.md) ^7.24.0
- [babel-plugin-add-module-exports](https://npm.io/package/babel-plugin-add-module-exports.md) ^1.0.0
- [@babel/plugin-proposal-decorators](https://npm.io/package/@babel/plugin-proposal-decorators.md) ^7.24.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 3.0.0-alpha.15 (latest) — 2026-09-04
- 3.0.0-alpha.13 — 2026-09-03
- 3.0.0-alpha.11 — 2026-09-01
- 2.0.0-alpha.3 — 2026-05-06
- 1.1.3 — 2022-04-23
- 0.3.30 — 2021-06-01
- 1.1.1 — 2021-05-31

## README

# brain-cli

## 介绍(Introduction)

在日常开发中，我们经常需要用到 webpack 作为打包工具，但每次新建一个项目，都需要去配置一次，虽然配置一次之后，后面都可以进行复制，但这样还是很繁琐。而且每个人水平不一样，不可能要求所有人都非常熟悉 webpack,然后在团队开发中，我们需要对配置统一。基于这些原因，
我们对 webpack 配置进行二次封装(js 文件打包拆分，css 单独打包，打包时间优化，反向代理，多入口处理等)，对外部暴露少量配置，用于满足一些特殊的要求。

## 使用

npm install brain-cli -D 或者 yarn add brain-cli

## barin-cli 优势

- 基于 webpack4.x、继承 react16.x 开发环境
- 支持多入口
- 不同入口页面 css/js 单独合并压缩
- 支持生成 ejs,jsp 模板页面
- 支持 webpack dll
- 支持增量构建
- 静态文件加戳
- 支持反向代理
- 支持对指定入口文件进行编译，打包
- 支持多套环境配置文件切换
- 支持 typescript

## 常用命令介绍

##### 编译命令

- brain-cli dev 运行开发模式
- brain-cli build dev 运行开发模式
- brain-cli build prod 生产环境
- brain-cli build test 测试环境
- brain-cli build dist 预发布环境(一般很少用到,特殊情况可以使用)
- brain-cli build -s 构建大小分析
- brain-cli build dev --apps=app1,app2 (编译指定入口文件)
- brain-cli build prod --apps=app1,app2 (编译指定入口文件)
- brain-cli build test --apps=app1,app2 (编译指定入口文件)

## .e-config

```js
const ProgressBarPlugin = require("progress-bar-webpack-plugin");
const chalk = require("chalk");
module.exports = {
  name: "test",
  open: true,
  defaultPort: 8001,
  server: "0.0.0.0",
  imageInLineSize: 8192,
  isTslint: true,
  publicPath: "/public/",
  devServer: {
    noInfo: true,
    proxy: {
      // '/main': {
      //     target: 'https://xxx.com/',
      //     //changeOrigin: true,
      //     secure: false,
      //         onProxyReq: (proxyReq, req, res) => {
      //             proxyReq.setHeader('host', 'xxx.com')
      //             proxyReq.setHeader('cookie', ' a=1111')
      //         }
      // },
    },
  },
  postcss: {
    // px2rem:{
    //     rootValue: 75,
    //     unitPrecision: 3,
    // },
    autoprefixer: {
      /**
       * 参考dora配置
       */
      browsers: [
        "last 2 versions",
        // "Firefox ESR",
        "Firefox >= 15",
        "> 1%",
        "ie >= 8",
        "not ie<=8",
      ],
    },
  },
  webpack: {
    dllConfig: {
      vendors: ["react", "react-dom", "invariant"],
    },
    disableReactHotLoader: false,
    happyPack: {
      open: false,
    },
    commonsChunkPlugin: ["common", "vendor"],
    plugins: [
      new ProgressBarPlugin({
        summary: false,
        format:
          `${chalk.green.bold("build [:bar]")}` +
          chalk.green.bold(":percent") +
          " (:elapsed seconds)",
        summaryContent: "",
      }),
    ],
  },
  babel: {
    query: {
      presets: [
        [
          "@babel/preset-env",
          {
            useBuiltIns: "usage", // entry usage  entry模式兼容IE11
            corejs: "3",
            targets: {
              browsers: [
                // 浏览器
                "last 2 versions",
                "ie >= 10",
              ],
            },
          },
        ],
        /*  "@babel/preset-env", */
        "@babel/preset-react",
      ],
      cacheDirectory: true,
      plugins: [
        "add-module-exports",
        "@babel/plugin-transform-runtime",
        [
          "@babel/plugin-proposal-decorators",
          {
            legacy: true,
          },
        ],
        [
          "import",
          {
            libraryName: "antd",
            style: true,
          },
        ],
      ],
    },
  },
  htmlWebpackPlugin: {
    title: "webApp" /**/,
  },
  apps: ["app1", "app2", "app3"],
};
```

#### webpack dll build

- brain-cli dll

### 配置参数

#### config.webpack.dllConfig

支持默认配置及自定义文件

1. vendors

```md
默认值 ['react'],如果需要配置复杂信息，则可以由数组变成对象
{
externalUrl: ''; //可选参数 当设置了此值，则 index.html dll 文件 url 变成外部链接
value:[],// 需要打包到 dll 文件的库
options: {
libraryTarget: 'umd' | 'var' | 'commonjs2' | 'commonjs' | 'amd' | 'window' | 'global' | 'this', // dll 文件模块输出模式
//当使用了 libraryTarget: "umd"，设置：true 会对 UMD 的构建过程中的 AMD 模块进行命名。否则就使用匿名的 define。
umdNamedDefine?: boolean;

    // globalObject为改变全局指向
      globalObject?:'this'

}, // 可选参数
}
```

2. customDll(自定义 dll 文件)

   ```md
   [
   {
   key: '' // dll 文件名称
   externalUrl?: '' // 当设置了此值，则 index.html dll 文件 url 变成外部链接
   value: [],// 需要打包到 dll 文件的库
   options?:{
   libraryTarget: 'umd' | 'var' | 'commonjs2' | 'commonjs' | 'amd' | 'window' | 'global' | 'this', // dll 文件模块输出模式
   //当使用了 libraryTarget: "umd"，设置：true 会对 UMD 的构建过程中的 AMD 模块进行命名。否则就使用匿名的 define。
   umdNamedDefine?: boolean;

          // globalObject为改变全局指向
          globalObject?:'this'
       }

   }
   ]
   ```

3. compileOptions(全局生效配置)

   ```md
   当在 dllConfig,配置了该参数，即可生效到所有 dll 文件，等同于配置了 options 参数，当 dll 文件指定了自身局部配置数据，则生效局部数据
   {
   libraryTarget: 'umd' | 'var' | 'commonjs2' | 'commonjs' | 'amd' | 'window' | 'global' | 'this', // dll 文件模块输出模式
   //当使用了 libraryTarget: "umd"，设置：true 会对 UMD 的构建过程中的 AMD 模块进行命名。否则就使用匿名的 define。
   umdNamedDefine?: boolean;

          // globalObject为改变全局指向
          globalObject?:'this'
       }
   ```

#### config.webpack.extend

首先它是一个函数，执行会抛出底层 loaders 等数据，当默认 loaders 不满足使用时，可以传入此配置用于扩展增强

```ts
interface ITransform{
  readonly cssModule: {
    modules: boolean;
    importLoaders: number;
    localIdentName: string;
  },
  readonly LoaderOptions: postcss_loader,
  execution:(cssModule,loader,currLoader)=>loader.use
}
interface IOptions{
  isDev:boolean;
  type:'hotLoader' | 'jsLoader' | 'tsLoader' | 'styleLoader';
  transform:ITransform
}
function (loaders:[], options:IOptions={
  isDev,loaderType,transform
})

// 例如
function (loaders,{ isDev, loaderType, transform }){
  const nodeModulesPath=path.resolve('../../', 'node_modules')
   if (type === 'js_loader') {
     if (loaders.length) {
            
      }
    }
    if (type === 'ts_loader' ) {
    }
    if (type === 'style_loader' && transform) {
      loaders.push({
            test: /\.css$/,
            use: transform.execution(null, null, null),
            include: [path.resolve(nodeModulesPath)],
          },)
    }
}
```

#### config.webpack.[tsCompilePlugin](https://github.com/TypeStrong/ts-loader#loader-options)

```ts
option: {
  getCustomTransformers: () => ({ // 示例， 可根据ts-loader options 文档去进行自由配置
    before: [
      createTransformer(),
      createTransformerReactJsxProps({
        components: [
          { name: 'LegionsProTable', props: 'uniqueUid', value: '' },
          { name: 'LegionsProForm', props: 'uniqueUid' },
          { name: 'LegionsProTabsForm', props: 'uniqueUid' },
          { name: 'LegionsProDataImport', props: 'uniqueUid' },
          { name: 'LegionsProConditions', props: 'uniqueUid' },
        ],
      }),
    ],
  }),
},
```

#### config.webpack.[happyPack](https://github.com/amireh/happypack)

> 1.配置信息

```ts
interface IHappyPack{
    /** 代表开启几个子进程去处理这一类型的文件，默认是3个，类型必须是整数。 */
    threads?: Number;
    /** 是否允许 HappyPack 输出日志，默认是 true。 */
    verbose?: Boolean;
    /** 代表共享进程池，即多个 HappyPack 实例都使用同一个共享进程池中的子进程去处理任务，以防止资源占用过多。 */
    threadPool?: any;
    /** 开启webpack --profile ,仍然希望HappyPack产生输出。 */
    verboseWhenProfiling?: boolean;
    /** 启用debug 用于故障排查。默认 false。 */
    debug?: boolean;
}
{
  open:false // 是否开启多线程
  /** js 线程配置 */
  procJs?: IHappyPack;
  /** ts 线程配置 */
  procTs?: IHappyPack;
}
```

> 2.开启多线程时，如果是编译 ts,tsx 文件，默认使用 ts-loader, 这时多进程下存在使用插件无法生效[问题](https://github.com/Igorbek/typescript-plugin-styled-components#forked-process-configuration)

```ts
const {
    createTransformer,
    createTransformerReactJsxProps,
  } = require('ts-plugin-legions');
// 2. create a transformer;
// the factory additionally accepts an options object which described below

// 3. create getCustomTransformer function
const getCustomTransformers = () => ({ before: [createTransformer([
    {
      libraryName: 'legions/store',
      bindings: ['StoreModules'],
    },
  ]),
  createTransformerReactJsxProps({
    components: [
      { name: 'LegionsProTable', props: 'uniqueUid', value: '' },
      { name: 'LegionsProForm', props: 'uniqueUid' },
      { name: 'LegionsProTabsForm', props: 'uniqueUid' },
      { name: 'LegionsProTabsForm', props: 'uniqueUid' },
      { name: 'LegionsProConditions', props: 'uniqueUid' },
      { name: 'HLDataImport', props: 'uniqueUid' },
    ],
  }),] });

// 4. export getCustomTransformers
module.exports = getCustomTransformers;
// webpack.ts-transformers.js


tsCompilePlugin: {
  option: {
    getCustomTransformers:path.join(__dirname, './webpack.ts-transformers.js'),
  },
},
```

## changeLog webpack4.x

## v1.1.3

- 【chore】优化loader加载器配置结构

## v1.1.1

- deprecate: 废弃部分不合适的参数配置 **disableHappyPack** , **cssModules**
- chore: 优化多进程由强制开启变成可以自由控制
- fix: 修复版本更新探测代码无法生效
- chore: 优化控制台输出信息
- chore: 升级 typescript 版本至 4.x

## v1.0.8-alpha.6(2020-12-01)

- feat: 新增 webpack 配置文件输出属性 output 支持自定义 library 及 libraryTarget
- feat: 新增 webpack dll 配置文件输出属性 output 支持自定义 libraryTarget 及其他属性
- feat: 新增 webpack dll 插件支持自定义
- fix: 修复 file-loader 插件通过 require 引入文件及样式引入文件,404 问题
- 升级 webpack 版本 4.x

## changeLog

## v0.3.28-beta.3 (2020-12-01)

- feat: 新增 webpack dll 配置文件输出属性 output 支持自定义 libraryTarget 及其他属性
- feat: 新增 webpack dll 插件支持自定义

## v0.3.28-beta.1 （2020-11-13）

- feat: 新增 webpack 配置文件输出属性 output 支持自定义 library 及 libraryTarget

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/brain-cli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
