Skip to content

Commit

Permalink
feat: add pwa
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Oct 27, 2020
1 parent 173d402 commit a1b9902
Show file tree
Hide file tree
Showing 6 changed files with 1,274 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ VITE_GLOB_API_URL=/api
# Interface prefix
VITE_GLOB_API_URL_PREFIX=

# use pwa
VITE_USE_PWA = false

# TODO use Cdn
VITE_USE_CDN = true
5 changes: 5 additions & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
## Wip

### ✨ Features

- 新增`pwa`功能,可在`.env.production`开启

### 🎫 Chores

- 升级 vite 版本为`v1.0.0.rc8`
- vite.config.ts 内部 plugins 抽取
- build 目录结构调整
- 依赖更新
- 文档更新

### ✨ Refactor

Expand Down
1 change: 1 addition & 0 deletions build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export function isSiteMode(): boolean {
export interface ViteEnv {
VITE_PORT: number;
VITE_USE_MOCK: boolean;
VITE_USE_PWA: boolean;
VITE_PUBLIC_PATH: string;
VITE_PROXY: [string, string][];
VITE_GLOB_APP_TITLE: string;
Expand Down
10 changes: 9 additions & 1 deletion build/vite/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Plugin as VitePlugin } from 'vite';
import type { Plugin as rollupPlugin } from 'rollup';

import { createMockServer } from 'vite-plugin-mock';
import { VitePWA } from 'vite-plugin-pwa';
import ViteHtmlPlugin from 'vite-plugin-html';
import PurgeIcons from 'vite-plugin-purge-icons';

Expand All @@ -17,7 +18,7 @@ import { GLOB_CONFIG_FILE_NAME } from '../../constant';

// gen vite plugins
export function createVitePlugins(viteEnv: ViteEnv) {
const { VITE_USE_MOCK, VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = viteEnv;
const { VITE_USE_MOCK, VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH, VITE_USE_PWA } = viteEnv;

const vitePlugins: VitePlugin[] = [];

Expand All @@ -43,6 +44,13 @@ export function createVitePlugins(viteEnv: ViteEnv) {
// vite-plugin-purge-icons
vitePlugins.push(PurgeIcons());

if (isProdFn() && VITE_USE_PWA) {
console.log('======================');
console.log(VITE_USE_PWA);
console.log('======================');
vitePlugins.push(VitePWA());
}

// vite-plugin-mock
if (isDevFn() && VITE_USE_MOCK) {
// open mock
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"vite-plugin-html": "^1.0.0-beta.2",
"vite-plugin-mock": "^1.0.4",
"vite-plugin-purge-icons": "^0.4.4",
"vite-plugin-pwa": "^0.1.2",
"vue-eslint-parser": "^7.1.1",
"yargs": "^16.1.0"
},
Expand Down
Loading

0 comments on commit a1b9902

Please sign in to comment.