Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
feat(cli): 开发模式下支持压缩文件 (#1102)
Browse files Browse the repository at this point in the history
* feat(cli): 支持 watch 模式启用文件压缩

* docs: 增加 minimize 的文档说明
  • Loading branch information
noyobo committed Jun 19, 2020
1 parent a8a23fe commit 167bba6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ Remax 默认为微信的每个 host 组件定义了嵌套层数。其中 `View`
}
}
```

## 小程序开发模式下 `remax build --watch` 无法真机预览?

开发模式下默认不压缩文件以保证快速的响应文件变更,如需在开发模式进行真机调试(压缩文件),可以使用 `--minimize``-m` 参数开启,会增加整体构建时间,请酌情使用。

注意:minimize 压缩不等同于生产模式!
6 changes: 3 additions & 3 deletions packages/remax-cli/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ export function run(options: Options): webpack.Compiler {
}
}

export function build(argv: Pick<Options, 'target' | 'watch' | 'notify' | 'port' | 'analyze'>) {
export function build(argv: Pick<Options, 'target' | 'watch' | 'notify' | 'port' | 'analyze' | 'minimize'>) {
const { target } = argv;

process.env.REMAX_PLATFORM = target;

const options = getConfig();
const { compressTemplate, ...options } = getConfig();

output.message(`\n⌨️ Remax v${remaxVersion()}\n`, 'green');
output.message(`🎯 平台 ${target}`, 'blue');

const result = run({ ...options, ...argv });
const result = run({ ...options, ...argv, compressTemplate: argv.minimize });

return result;
}
2 changes: 1 addition & 1 deletion packages/remax-cli/src/build/webpack/config.mini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function webpackConfig(api: API, options: Options, target: Platfo
},
},
});
config.optimization.minimize(false);
config.optimization.minimize(options.minimize ?? false);

config.module
.rule('config')
Expand Down
6 changes: 6 additions & 0 deletions packages/remax-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export function run(args: any, callback?: yargs.ParseCallback) {
type: 'boolean',
default: false,
})
.option('minimize', {
describe: '最小化文件',
alias: 'm',
type: 'boolean',
default: false,
})
.showHelpOnFail(false);

return cli.parse(args, callback);
Expand Down
1 change: 1 addition & 0 deletions packages/remax-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Options {
watch?: boolean;
target?: Platform;
analyze?: boolean;
minimize?: boolean;
}

export type Config = Partial<Options>;
Expand Down

1 comment on commit 167bba6

@vercel
Copy link

@vercel vercel bot commented on 167bba6 Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.