Skip to content

Commit

Permalink
add server build
Browse files Browse the repository at this point in the history
  • Loading branch information
Terwer committed Feb 13, 2019
1 parent 99ce255 commit e0a0528
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 22 deletions.
4 changes: 0 additions & 4 deletions src/main/webapp/build/webpack.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
const merge = require("webpack-merge");
const base = require("./webpack.base.config");

console.log("webpack base=>", base);

const clientConfig = merge(base.webpackCnfig, {
entry: "./src/entry-client.js",
output: {
filename: "js/[name].[chunkhash:6].js"
}
});

console.log("webpack clientConfig=>", clientConfig);

module.exports = clientConfig;
10 changes: 1 addition & 9 deletions src/main/webapp/build/webpack.nossr.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
const merge = require("webpack-merge");
const base = require("./webpack.base.config");

console.log("webpack base=>", base);

const appConfig = merge(base.webpackCnfig, {
entry: "./src/app.js",
entry: "./src/nossr.js",
output: {
filename: "js/[name].[hash:6].js"
},
Expand All @@ -15,10 +13,4 @@ const appConfig = merge(base.webpackCnfig, {
}
});

console.log("webpack appConfig=>", appConfig);
console.log(
"base.config.isProduction in appConfig=>",
base.config.isProduction
);

module.exports = appConfig;
4 changes: 0 additions & 4 deletions src/main/webapp/build/webpack.server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
const merge = require("webpack-merge");
const base = require("./webpack.base.config");

console.log("webpack base=>", base);

const serverConfig = merge(base.webpackCnfig, {
entry: "./src/entry-server.js",
output: {
filename: "server-bundle.js"
}
});

console.log("webpack serverConfig=>", serverConfig);

module.exports = serverConfig;
2 changes: 1 addition & 1 deletion src/main/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"clean": "rimraf dist",
"lint": "eslint --ext .js,.vue,.html --ignore-path .gitignore --ignore-pattern !.eslintrc.js --ignore-pattern !.babelrc.js . --fix --color",
"nossr": "cross-env NODE_ENV=development webpack-dev-server --config build/webpack.nossr.config.js --hot --inline --progress",
"build:nossr": "yarn clean && cross-env NODE_ENV=production webpack --config build/webpack.nossr.config.js",
"build:nossr": "yarn clean && cross-env NODE_ENV=production webpack --config build/webpack.nossr.config.js --progress --hide-modules",
"dev": "node server",
"build": "yarn clean && yarn build:client && yarn build:server",
"build:client": "cross-env NODE_ENV=production webpack --config build/webpack.client.config.js --progress --hide-modules",
Expand Down
23 changes: 19 additions & 4 deletions src/main/webapp/src/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import Vue from "vue";
import App from "./App.vue";
new Vue({
el: "#app",
render: h => h(App)
});

/**
* Expose a factory function that creates a fresh set of
* app instances on each call (which is called for each SSR request)
* @param ssrContext
* @returns {{app: Vue | CombinedVueInstance<V, object, object, object, Record<never, any>>}}
*/
export function createApp(ssrContext) {
// create the app instance.
const app = new Vue({
render: h => h(App)
});

// expose the app
// note we are not mounting the app here, since bootstrapping will be
// different depending on whether we are in a browser or on the server.
return { app };
// return { app, router, store }
}
7 changes: 7 additions & 0 deletions src/main/webapp/src/entry-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createApp } from "./app";

// noinspection JSCheckFunctionSignatures
const { app } = createApp();

// actually mount to DOM
app.$mount("#app");
10 changes: 10 additions & 0 deletions src/main/webapp/src/entry-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createApp } from "./app";

// This exported function will be called by `bundleRenderer`.
// return a Promise that resolves to the app instance.
export default context => {
return new Promise((resolve, reject) => {
const { app } = createApp(context);
resolve(app);
});
};
7 changes: 7 additions & 0 deletions src/main/webapp/src/nossr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createApp } from "./app";

// noinspection JSCheckFunctionSignatures
const { app } = createApp();

// actually mount to DOM
app.$mount("#app");

0 comments on commit e0a0528

Please sign in to comment.