Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
feat(cli): production mode and rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
NewFuture committed Jun 25, 2019
1 parent 3bfe767 commit 50f8ec7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ npm build npm dependencies to dist <编译npm依赖>

```
--version show version number <查看本版号> [boolean]
--release production mode <发布模式会优化压缩> [boolean] [default: false]
--production production mode <发布模式会优化压缩> [boolean] [default: false]
--src source folder <源文件目录> [string] [default: "src"]
--dist output folder <编译输出目录> [string] [default: "dist"]
--exclude ignored files <编译忽略文件(夹)> [array]
Expand All @@ -80,10 +80,11 @@ npm build npm dependencies to dist <编译npm依赖>
npx miniprogram-build --config=config.dev.json
```

- 使用`config.prod.json`生产环境开启优化重新编译,rebuild for production release with `config.prod.json`
- 使用`config.prod.json`生产环境开启优化重新编译,rebuild for production with `config.prod.json`

> 如果 `production` 参数未指定, 环境变量中 NODE_ENV 为 `production``prod`时同样置为 `true`
```bash
npx miniprogram-build build --config=./config.prod.json --release
npx miniprogram-build build --config=./config.prod.json --production
```

- 编译替换`{{APP_ID}}`为1234567, compile the source and replace template var _{_*{*`APP_ID`*}*_}_ with 123456
Expand All @@ -94,7 +95,7 @@ npx miniprogram-build compile --var.APP_ID=1234567

```json
{
"release": false,
"production": false,
"src": "src",
"dist": "dist",
"assets": "assets",
Expand Down
10 changes: 7 additions & 3 deletions bin/mp-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ var argv = require("yargs")
.alias("h", "help")
.describe("version", od(`show version number ${odc("<查看本版号>")}`))
.epilog(colors.italic(colors.gray("2018 - " + new Date().getFullYear()) + " " + colors.cyan.dim("@ NewFuture")))
.option("release", {
.option("production", {
describe: od(`production mode ${odc("<发布模式会优化压缩>")}`),
default: false,
default: process.env.NODE_ENV === "production" || process.env.NODE_ENV === "prod",
boolean: true,
})
.alias("production", "release")
.option("src", {
describe: od(`source folder ${odc("<源文件目录>")}`),
default: "src",
Expand Down Expand Up @@ -101,10 +102,13 @@ var argv = require("yargs")

Object.assign(config.default, argv, { $0: undefined, _: undefined });

// console.log(argv['config'])
console.log(argv['config'])
if (argv._.length === 1 && argv._[0] === "init") {
config.save(config.default);
} else {
if (config.default.production) {
process.env.NODE_ENV = "production"
}
const tasks = require("../src/task")
tasks.$execute(argv._.length === 0 ? ["dev"] : argv._);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"yargs": "^13.2.4"
},
"optionalDependencies": {
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-typescript": "^1.0.0",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-node-resolve": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports.auto = autoLoad;
*/
module.exports.default = {
// debug: true,
release: false,
production: false,
src: 'src',
dist: 'dist',
assets: 'assets',
Expand Down

0 comments on commit 50f8ec7

Please sign in to comment.