forked from lavas-project/lavas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/lavas-project/lavas
- Loading branch information
Showing
10 changed files
with
122 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,22 @@ | |
|
||
======= | ||
|
||
## [2.1.8-rc.2] - 2018-1-3 | ||
|
||
### Changed | ||
|
||
- [Feature] Add `build.skeleton` in config. In SPA, you can toggle skeleton feature by `build.skeleton.enable` and change `core/Skeleton.vue` with `build.skeleton.path`. | ||
- [Feature] Inject some lines in `core/service-worker.js`: | ||
- Auto prefix when using `publicPath`. eg. `importScripts('${publicPath}static/js/workbox-sw.prod.v2.1.2.js');` | ||
- Auto add `workboxSW.router.registerNavigationRoute();` at the end of the file. You don't need to modify when switching between `SSR` and `SPA` manually. | ||
|
||
## [2.1.8-rc.1] - 2018-1-2 | ||
|
||
### Changed | ||
|
||
- [Fix] `cssExtract` in production mode. | ||
- [Fix] Update to [email protected]. | ||
- [Breaking Change] Remove `entry` in config. | ||
|
||
## [2.0.7-rc.4] - 2017-12-20 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
* @file utils.workbox.js | ||
* @author lavas | ||
*/ | ||
import {basename} from 'path'; | ||
import {basename, join} from 'path'; | ||
import {readFileSync, writeFileSync} from 'fs-extra'; | ||
import WorkboxWebpackPlugin from 'workbox-webpack-plugin'; | ||
|
||
export const WORKBOX_PATH = require.resolve('workbox-sw'); | ||
|
||
|
@@ -20,3 +22,47 @@ export function getWorkboxFiles(isProd) { | |
`${filename}.map` | ||
]; | ||
} | ||
|
||
/** | ||
* use workbox-webpack-plugin | ||
* | ||
* @param {Object} webpackConfig webpack config | ||
* @param {Object} workboxConfig workbox config | ||
* @param {Object} lavasConfig lavas config | ||
*/ | ||
export function useWorkbox(webpackConfig, workboxConfig, lavasConfig) { | ||
let {swSrc, appshellUrl} = workboxConfig; | ||
let {buildVersion, build: {publicPath, ssr}, globals} = lavasConfig; | ||
|
||
// service-worker provided by user | ||
let serviceWorkerContent = readFileSync(swSrc); | ||
|
||
// import workbox-sw | ||
let importWorkboxClause = `importScripts('${publicPath}static/js/workbox-sw.prod.v2.1.2.js');`; | ||
serviceWorkerContent = importWorkboxClause + serviceWorkerContent; | ||
|
||
// register navigation in the end | ||
let registerNavigationClause; | ||
if (ssr) { | ||
registerNavigationClause = `workboxSW.router.registerNavigationRoute('${appshellUrl}');`; | ||
|
||
// add build version to templatedUrls | ||
if (appshellUrl) { | ||
workboxConfig.templatedUrls = { | ||
[appshellUrl]: `${buildVersion}` | ||
}; | ||
} | ||
} | ||
else { | ||
registerNavigationClause = `workboxSW.router.registerNavigationRoute('/index.html');`; | ||
} | ||
serviceWorkerContent += registerNavigationClause; | ||
|
||
// write new service worker in .lavas/sw.js | ||
let tempSwSrc = join(globals.rootDir, './.lavas', 'sw-temp.js'); | ||
writeFileSync(tempSwSrc, serviceWorkerContent, 'utf8'); | ||
workboxConfig.swSrc = tempSwSrc; | ||
|
||
// use [email protected] | ||
webpackConfig.plugins.push(new WorkboxWebpackPlugin(workboxConfig)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,10 @@ import CopyWebpackPlugin from 'copy-webpack-plugin'; | |
import VueSSRServerPlugin from 'vue-server-renderer/server-plugin'; | ||
import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer'; | ||
import SWRegisterWebpackPlugin from 'sw-register-webpack-plugin'; | ||
import WorkboxWebpackPlugin from 'workbox-webpack-plugin'; | ||
|
||
import {vueLoaders, styleLoaders} from './utils/loader'; | ||
import {assetsPath} from './utils/path'; | ||
import {WORKBOX_PATH, getWorkboxFiles} from './utils/workbox'; | ||
import {WORKBOX_PATH, getWorkboxFiles, useWorkbox} from './utils/workbox'; | ||
import {LAVAS_DIRNAME_IN_DIST, SERVER_BUNDLE, ASSETS_DIRNAME_IN_DIST} from './constants'; | ||
|
||
import fs from 'fs'; | ||
|
@@ -168,7 +167,7 @@ export default class WebpackConfig { | |
* @return {Object} client base config | ||
*/ | ||
client(buildConfig = {}) { | ||
let {buildVersion, ssr, globals, build, manifest, serviceWorker: workboxConfig} = this.config; | ||
let {buildVersion, globals, build, manifest, serviceWorker: workboxConfig} = this.config; | ||
|
||
/* eslint-disable fecs-one-var-per-line */ | ||
let {publicPath, filenames, cssSourceMap, cssMinimize, cssExtract, | ||
|
@@ -249,15 +248,9 @@ export default class WebpackConfig { | |
] | ||
}); | ||
|
||
// Use workbox in prod mode. | ||
if (this.isProd && workboxConfig) { | ||
if (workboxConfig.appshellUrls && workboxConfig.appshellUrls.length) { | ||
workboxConfig.templatedUrls = {}; | ||
workboxConfig.appshellUrls.forEach(appshellUrl => { | ||
workboxConfig.templatedUrls[appshellUrl] = `${buildVersion}`; | ||
}); | ||
} | ||
clientConfig.plugins.push(new WorkboxWebpackPlugin(workboxConfig)); | ||
// Use [email protected] in prod mode. | ||
useWorkbox(clientConfig, workboxConfig, this.config); | ||
} | ||
|
||
// Copy static files to /dist. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters