Skip to content

Commit

Permalink
use npm-run-all
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Feb 16, 2018
1 parent 5b7e12e commit 6c68f41
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
10 changes: 5 additions & 5 deletions docs/webpack.md → docs/bundler.md
@@ -1,6 +1,6 @@
# Webpack
# Bundler

By default we don't use a bundler, so files for renderer process are populated at `app/renderer` folder. If you enabled webpack support, that folder will be automatically generated from `src` folder using webpack:
By default we don't use a bundler, so files for renderer process are populated at `app/renderer` folder. If you enabled bundler support, that folder will be automatically generated from `src` folder using webpack or parcel, for webpack:

- poi.config.js
- src/App.vue
Expand All @@ -15,12 +15,12 @@ And you will get 4 addtional npm scripts:
- `npm run main`: Run Electron app (main process) to load `http://localhost:4000` in development or `app/renderer/index.html` in production.
- `npm run dev`: Run `npm run main` and `npm run renderer` concurrently.

In development, you only need to run `npm run main` and `npm run renderer` side by side. Or do yourself a favor using `npm run dev` which runs the above npm scripts `concurrenly` so that you only need to open one terminal tab.
In development, you only need to run `npm run main` and `npm run renderer` side by side. Or do yourself a favor using `npm run dev` which runs the above npm scripts concurrenly so that you only need to open one terminal tab.

**Note that you need to re-run `npm run main` or `npm run dev` after update the code of main process.**

If you're running `npm run dev`, you may need to refresh electron window when `npm run renderer` is ready since webpack might take seconds or more to finish bundling for the first time.

## Packaging

Before packaging your app, you need to run `npm run build` to build the code of renderer process to `app/renderer` directory.

The packaged app will be available at `dist` directory.
10 changes: 6 additions & 4 deletions sao.js
Expand Up @@ -88,9 +88,11 @@ module.exports = {
'src-parcel/**': 'bundler === "parcel"',
'src-poi/**': 'bundler === "poi"'
},
async post(ctx) {
ctx.gitInit()
ctx.yarnInstall()
ctx.showTip()
async post({ gitInit, yarnInstall, log, chalk, pm }) {
gitInit()
yarnInstall()
log.info(`To develop the app: ${chalk.cyan(pm)} run dev`)
log.info(`To build for production: ${chalk.cyan(pm)} run build`)
log.info(`To distribute: ${chalk.cyan(pm)} run dist`)
}
}
11 changes: 4 additions & 7 deletions template/package.json
Expand Up @@ -11,12 +11,9 @@
"renderer": "poi",<% } else if (bundler ==='parcel') { %>
"build": "parcel build src/index.html --target electron -d app/renderer --public-url ./",
"renderer": "parcel src/index.html --target electron --port 4000",<% } %>
"dev": "concurrently \"npm run main\" \"npm run renderer\" -k"<% } %>,
"dev": "run-p main renderer"<% } %>,
"main": "electron app/index.js"<% if (distribute) { %>,
"dist": "npm run dist:mac && npm run dist:deb && npm run dist:win",
"dist:mac": "build --mac",
"dist:linux": "build --linux deb tar.xz",
"dist:win": "build --win --ia32"<% } %>
"dist": "build"<% } %>
},<% if (distribute) { %>
"build": {
"appId": "com.<%= username %>.<%= name %>",
Expand All @@ -35,8 +32,8 @@
"category": "public.app-category.developer-tools"
}
},<% } %>
"devDependencies": {
"concurrently": "^3.5.0",
"devDependencies": {<% if (bundler) { %>
"npm-run-all": "^4.1.2",<% } %>
"electron": "^1.6.10"<% if (distribute) { %>,
"electron-builder": "^18.0.1",
"electron-builder-squirrel-windows": "^18.0.0"<% } %><% if (bundler === 'poi') { %>,
Expand Down
9 changes: 3 additions & 6 deletions test/snapshots/test.js.md
Expand Up @@ -55,12 +55,9 @@ Generated by [AVA](https://ava.li).
"test": "echo lol",␊
"build": "parcel build src/index.html --target electron -d app/renderer --public-url ./",␊
"renderer": "parcel src/index.html --target electron --port 4000",␊
"dev": "concurrently \\"npm run main\\" \\"npm run renderer\\" -k",␊
"dev": "run-p main renderer",␊
"main": "electron app/index.js",␊
"dist": "npm run dist:mac && npm run dist:deb && npm run dist:win",␊
"dist:mac": "build --mac",␊
"dist:linux": "build --linux deb tar.xz",␊
"dist:win": "build --win --ia32"␊
"dist": "build"␊
},␊
"build": {␊
"appId": "com.username.project",␊
Expand All @@ -80,7 +77,7 @@ Generated by [AVA](https://ava.li).
}␊
},␊
"devDependencies": {␊
"concurrently": "^3.5.0",␊
"npm-run-all": "^4.1.2",␊
"electron": "^1.6.10",␊
"electron-builder": "^18.0.1",␊
"electron-builder-squirrel-windows": "^18.0.0",␊
Expand Down
Binary file modified test/snapshots/test.js.snap
Binary file not shown.

0 comments on commit 6c68f41

Please sign in to comment.