Skip to content

Commit

Permalink
Merge branch 'hotfix/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
SolarLiner committed Jan 13, 2019
2 parents d3d5f85 + ce39bbe commit 5321e34
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ module.exports = (api, projectOptions) => {

function chain(api, projectOptions) {
return config => {
const options = createOptions(api, projectOptions);
const options = createPluginOptions(api, projectOptions);
if (options.onlyProduction && process.env.NODE_ENV !== "production") {
return;
}
const renderer = createRenderer(api, projectOptions);
const paths = resolvePaths(api, projectOptions.outputDir, projectOptions.assetsDir);
const prerenderOptions = {
Expand All @@ -31,16 +34,18 @@ function chain(api, projectOptions) {
}
};
config.plugin("pre-render").use(PrerenderSPAPlugin, [prerenderOptions]);
config.plugin("html").tap(args => {
args[0].template = api.resolve("public/index.html");
args[0].filename = "app.html";
return args;
});
if (process.env.NODE_ENV === "production") {
config.plugin("html").tap(args => {
args[0].template = api.resolve("public/index.html");
args[0].filename = "app.html";
return args;
});
}
};
}

function createRenderer(api, projectOptions) {
const rendererConfig = createConfig(api, projectOptions);
const rendererConfig = createRendererConfig(api, projectOptions);
const renderer = new Renderer(rendererConfig);
renderer.preServer = Prerenderer => {
if (projectOptions.baseUrl) {
Expand Down Expand Up @@ -70,11 +75,8 @@ function createRenderer(api, projectOptions) {
return renderer;
}

function createConfig(api, projectOptions) {
let options = createOptions(api, projectOptions);
if (options.onlyProduction && process.env.NODE_ENV !== "production") {
return;
}
function createRendererConfig(api, projectOptions) {
let options = createPluginOptions(api, projectOptions);
let rendererConfig = {
headless: options.headless,
maxConcurrentRoutes: options.parallel ? 4 : 1
Expand All @@ -88,29 +90,29 @@ function createConfig(api, projectOptions) {
return rendererConfig;
}

function createOptions(api, projectOptions) {
function createPluginOptions(api, projectOptions) {
let options;
let oldConfigPath = api.resolve(".prerender-spa.json");
try {
options = pickle(projectOptions, CONFIG_OBJ_PATH);
if (existsSync(oldConfigPath)) {
Object.assign(options, JSON.parse(readFileSync(oldConfigPath).toString("utf-8")));
}
}
catch {
} catch {
if (existsSync(oldConfigPath)) {
options = JSON.parse(readFileSync(oldConfigPath).toString("utf-8"));
}
}
return options;
// return options; // TODO: Fix #16 permanently
return Object.assign(options, { onlyProduction: true }); // Force disable on development build, workaround for #16
}

function resolvePaths(api, baseUrl, assetsDir) {
return {
outputDir: api.resolve(baseUrl),
staticDir: api.resolve(baseUrl),
assetsDir: api.resolve(path.join(baseUrl, assetsDir)),
indexPath: api.resolve(path.join(baseUrl, "app.html"))
indexPath: api.resolve(path.join(baseUrl, process.env.NODE_ENV === "production" ? "app.html" : "index.html"))
};
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-cli-plugin-prerender-spa",
"version": "1.1.0",
"version": "1.1.1",
"description": "Vue CLI plugin to add prerendering to your application",
"main": "index.js",
"author": {
Expand Down

0 comments on commit 5321e34

Please sign in to comment.