Skip to content

Commit 6a51aa3

Browse files
committed
Merge branch 'release/1.1.3'
2 parents 5321e34 + e4c87c1 commit 6a51aa3

File tree

8 files changed

+1365
-30
lines changed

8 files changed

+1365
-30
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [["@babel/preset-env", { "targets": { "node": "8.9" } }]]
3+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,6 @@ typings/
7171

7272
# Serverless directories
7373
.serverless
74+
75+
# Babel files output
76+
/*.js

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
Add `prerender-spa-plugin` into your Vue application with zero configuration.
44

5+
![](https://img.shields.io/david/solarliner/vue-cli-plugin-prerender-spa.svg)
6+
![](https://img.shields.io/david/dev/solarliner/vue-cli-plugin-prerender-spa.svg)
7+
![](https://img.shields.io/npm/v/vue-cli-plugin-prerender-spa.svg)
8+
![](https://img.shields.io/github/commits-since/solarliner/vue-cli-plugin-prerender-spa/1.1.3.svg)
9+
510
**Looking for a co-maintainer**: I'm continuing to maintain this project, hoever
611
I still would like help on some of the issues, and generally to help me keep this
712
plugin going as it's getting more and more popular. If you think you can help,

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{
22
"name": "vue-cli-plugin-prerender-spa",
3-
"version": "1.1.1",
3+
"version": "1.1.3",
44
"description": "Vue CLI plugin to add prerendering to your application",
55
"main": "index.js",
66
"author": {
77
"name": "Nathan Graule",
88
"email": "[email protected]"
99
},
10+
"scripts": {
11+
"build": "babel src --out-dir .",
12+
"prepack": "yarn build"
13+
},
1014
"license": "MIT",
1115
"repository": "https://github.com/SolarLiner/vue-cli-plugin-prerender-spa",
1216
"keywords": [
@@ -25,7 +29,14 @@
2529
],
2630
"private": false,
2731
"dependencies": {
28-
"javascript-stringify": "^1.6.0",
2932
"prerender-spa-plugin": "^3.2.1"
33+
},
34+
"devDependencies": {
35+
"@babel/cli": "^7.2.3",
36+
"@babel/core": "^7.2.2",
37+
"@babel/preset-env": "^7.2.3"
38+
},
39+
"engines": {
40+
"node": ">=8.9"
3041
}
3142
}

generator/index.js renamed to src/generator.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = (api, options) => {
1+
export default generate;
2+
module.exports = generate;
3+
4+
function generate(api, options) {
25
api.onCreateComplete(() => {
36
const fs = require("fs");
47

index.js renamed to src/index.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
//@ts-check
2-
const { exists, existsSync, readFileSync } = require("fs");
3-
const path = require("path");
2+
import { exists, existsSync, readFileSync } from "fs";
3+
import { extname, join, basename } from "path";
44

5-
const PrerenderSPAPlugin = require("prerender-spa-plugin");
6-
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer;
5+
import PrerenderSPAPlugin, { PuppeteerRenderer } from "prerender-spa-plugin";
6+
const Renderer = PuppeteerRenderer;
77

88
const CONFIG_OBJ_PATH = "pluginOptions.prerenderSpa";
99

10-
module.exports = (api, projectOptions) => {
10+
export default entry;
11+
module.exports = entry;
12+
13+
function entry(api, projectOptions) {
1114
api.chainWebpack(chain(api, projectOptions));
12-
};
15+
}
1316

1417
function chain(api, projectOptions) {
1518
return config => {
@@ -25,8 +28,8 @@ function chain(api, projectOptions) {
2528
renderer,
2629
postProcess: renderedRoute => {
2730
const route = renderedRoute.route;
28-
if (route[route.length - 1] !== "/" && path.extname(route) === "") {
29-
renderedRoute.outputPath = path.join(paths.outputDir || paths.staticDir, `${route}.html`);
31+
if (route[route.length - 1] !== "/" && extname(route) === "") {
32+
renderedRoute.outputPath = join(paths.outputDir || paths.staticDir, `${route}.html`);
3033
}
3134
const userPostProcess =
3235
options.postProcess && typeof options.postProcess === "function" ? options.postProcess : noop;
@@ -48,8 +51,9 @@ function createRenderer(api, projectOptions) {
4851
const rendererConfig = createRendererConfig(api, projectOptions);
4952
const renderer = new Renderer(rendererConfig);
5053
renderer.preServer = Prerenderer => {
51-
if (projectOptions.baseUrl) {
52-
const prefix = projectOptions.baseUrl;
54+
const publicPath = projectOptions.publicPath || projectOptions.baseUrl;
55+
if (publicPath) {
56+
const prefix = publicPath;
5357
const server = Prerenderer._server._expressServer;
5458
server.use((req, res, next) => {
5559
if (req.url.indexOf(prefix) === 0) {
@@ -61,9 +65,9 @@ function createRenderer(api, projectOptions) {
6165
if (projectOptions.pages) {
6266
const server = Prerenderer._server._expressServer;
6367
server.get("*", (req, res, next) => {
64-
if (!path.extname(req.url)) {
68+
if (!extname(req.url)) {
6569
const filePath = api.resolve(
66-
`${projectOptions.outputDir}${req.url}${path.basename(req.url) ? ".html" : "index.html"}`
70+
`${projectOptions.outputDir}${req.url}${basename(req.url) ? ".html" : "index.html"}`
6771
);
6872
exists(filePath, exists => (exists ? res.sendFile(filePath) : next()));
6973
return;
@@ -111,8 +115,8 @@ function resolvePaths(api, baseUrl, assetsDir) {
111115
return {
112116
outputDir: api.resolve(baseUrl),
113117
staticDir: api.resolve(baseUrl),
114-
assetsDir: api.resolve(path.join(baseUrl, assetsDir)),
115-
indexPath: api.resolve(path.join(baseUrl, process.env.NODE_ENV === "production" ? "app.html" : "index.html"))
118+
assetsDir: api.resolve(join(baseUrl, assetsDir)),
119+
indexPath: api.resolve(join(baseUrl, process.env.NODE_ENV === "production" ? "app.html" : "index.html"))
116120
};
117121
}
118122

prompts.js renamed to src/prompts.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = [
1+
const prompts = [
22
{
33
name: "renderRoutes",
44
type: "input",
@@ -32,3 +32,6 @@ module.exports = [
3232
default: true
3333
}
3434
];
35+
36+
export default prompts;
37+
module.exports = prompts;

0 commit comments

Comments
 (0)