Includes:
- Webpack 4
- polka web-server
- Vue 2 with SSR, Vuex and vue-loader
- Stylus with kouto-swiss
- Axios
- Pug
- SVG sprites builder
- ESlint with pre-push hook
npm i
# development server on localhost:8080
npm run dev
# production build
npm run build
# production server on localhost:8080
npm start
.env.dev
contains environment variables used for local development. You can change application port,
API base URL for server and client and enable/disable proxy (http-proxy-middleware).
For production builds you should provide same environment variables yourself.
Alternatively you can use .env
after these steps:
- Move
dotenv
fromdevDependencies
todependencies
. - Create
.env
file with production config. - Run
npm start
orNODE_ENV=production node -r dotenv/config index
.
See setup-proxy.js
for description.
index.js
- application serversetup-proxy.js
-http-proxy-middleware
setupbuild/
- build related codesetup-dev-server
- development server setupsvg-sprite
- svg sprite generation script, gathers icons fromsrc/assets/svg-icons
and compiles them intosrc/assets/sprite.svg
webpack/
- webpack config,base
- common,server
for server with SSR,client
for browser
dist/
- production build filessrc/
assets/
- application static assets (images, fonts, icons etc.)sprite.svg
- generated sprites file,require('src/assets/sprite.svg')
will return file contents stringfonts/
- guess whatimages/
- static images (backgrounds, patterns etc.)svg-icons/
- contains SVG icons for the sprite
entry/
- main entry pointsapp
- shared between server and client, exports a factory function returning root component instance, mixes it withapp.vue
client
- client entryserver
- server entry
components/
- vue componentspages/
- components here are implicitly attached to routes same with componets' file names (excluding leading_
in file or folder names and404.vue
which will be used as a catch-all route)filters/
- vue filters registered implicitly viaVue.filter()
directives/
- vue directives registered implicitly viaVue.directive()
store/
- Vuex storage,index
returns a factory function returning configured Vuex store instanceutils/
- common utility functionsindex
- common utility functionsssr
- SSR related functions and mixins
app.vue
- application root component, implicitly mixed withentry\app
http
- exports http client instance (Axios)layout.pug
- application HTML layoutrouter
- exports a factory function returning vue-router instanceshared.styl
- globally included stylus file (for variables, mixins, etc.)
Every component within src/pages
directory can use some special features providing full SSR support:
-
component.routePath
, String - additional route suffix. Usually used to provide dynamic route segments. You can use any string allowed for the vue-router path definition. All dynamic segments are automatically mapped to componentprops
. -
component.routeMeta
, Object -route.meta
. IncludestatusCode
here to modify an HTTP status returned with SSR. 404 route includes 404 status code by default. -
component.prefetch({ store, props, route })
, function (store
- vuex store instance,props
- route params,route
- current route object).Must return a promise. Allows some async routine before actual application rendering on server side. To pass any data to component: resolve promise with needed data and add corresponding
component.data
fields with their initial values to prevent ...property or method not defined... error. Automatically called on client side frombeforeMount
andbeforeRouteChange
hooks as well. Seesrc/utils/ssr
mixin. -
Boolean
prefetching
data field indicates when prefetch is running.IMPORTANT: there is no component context within
prefetch
function because component instance is not created yet! That means you should not try to usethis
.
prefetch
also works on the root component (src/app.vue
) with some restrictions:
- no way to pass component data (only store can be affected).