Skip to content

feat(onError): adding basic onError cb #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
aae3c8d
master: adding basic onError cb
Jun 18, 2019
bf31f43
feat(adding_mrs): adding latest mr's
Aug 23, 2019
7c8dd74
feat(updating_eslint): updating dependencies
Aug 26, 2019
6dd5a0b
feat(copy_url_on_start): integrate mr
Aug 27, 2019
0d5aa37
Merge pull request #1 from sumcumo/feat/updating_eslint
svewag Aug 27, 2019
812ef1f
Merge pull request #2 from sumcumo/feat/copyUrlOnStart
svewag Aug 27, 2019
1f85d46
Update chalk to version 2.4.2
depfu[bot] Aug 27, 2019
4328c60
Merge pull request #4 from sumcumo/depfu/update/yarn/chalk-2.4.2
ma-jahn Aug 27, 2019
78a4d48
Update compression to version 1.7.4
depfu[bot] Aug 27, 2019
ac5b250
Update portfinder to version 1.0.23
depfu[bot] Aug 27, 2019
e4d0060
Update eslint-plugin-import to version 2.18.2
depfu[bot] Aug 27, 2019
c00f91f
Update loader-utils to version 1.2.3
depfu[bot] Aug 27, 2019
974235c
feat(copy_url_on_start): integrate mr
Aug 27, 2019
060e2f6
chore(package.json): amending name and description
Aug 27, 2019
a1d8f1a
Merge pull request #5 from sumcumo/depfu/update/yarn/compression-1.7.4
ma-jahn Aug 27, 2019
4a0e5ce
Merge pull request #6 from sumcumo/depfu/update/yarn/portfinder-1.0.23
ma-jahn Aug 27, 2019
e9c8c3e
Update express to version 4.17.1
depfu[bot] Aug 27, 2019
7702cca
Update webpack-merge to version 4.2.1
depfu[bot] Aug 27, 2019
f9cfdc1
Merge pull request #7 from sumcumo/depfu/update/yarn/eslint-plugin-im…
ma-jahn Aug 27, 2019
906bb31
Merge pull request #12 from sumcumo/depfu/update/yarn/webpack-merge-4…
ma-jahn Aug 27, 2019
09aaff4
Merge pull request #9 from sumcumo/depfu/update/yarn/loader-utils-1.2.3
ma-jahn Aug 27, 2019
8bb7f16
Merge pull request #8 from sumcumo/depfu/update/yarn/express-4.17.1
ma-jahn Aug 27, 2019
7932331
Merge branch 'master' of https://github.com/sumcumo/vue-cli-plugin-ssr
Aug 27, 2019
744437d
chore(vuepress): moving from yarn to npm and using latest vuepress
Aug 27, 2019
e5c66ec
Merge branch 'master' of https://github.com/sumcumo/vue-cli-plugin-ssr
Aug 27, 2019
1f5e3d2
chore(npm): moving from yarn to npm
Aug 27, 2019
a5de09e
Merge pull request #17 from sumcumo/chore/npm
ma-jahn Aug 27, 2019
165e7f4
Merge branch 'chore/npm' into chore/vuepress
Aug 27, 2019
42d2fc9
Merge pull request #18 from sumcumo/chore/vuepress
ma-jahn Aug 27, 2019
2ef1b86
Update webpack-merge to version 4.2.2
depfu[bot] Sep 6, 2019
a1d85de
Merge pull request #21 from sumcumo/depfu/update/npm/webpack-merge-4.2.2
ma-jahn Sep 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 25 additions & 39 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,34 @@
module.exports = {
dest: 'docs/.vuepress/dist',
base: '/',
serviceWorker: true,
title: 'Vue CLI SSR plugin',
description: 'Dead Simple Server-Side-Rendering',
head: [
['link', { rel: 'icon', href: '/logo.png' }],
['link', { rel: 'icon', href: '/favicon.png' }]
],
locales: {
'/': {
lang: 'en-US',
title: 'Vue CLI SSR plugin',
description: 'Dead Simple Server-Side-Rendering',
},
},
evergreen: true,
displayAllHeaders: true,
sidebarDepth: 3,
themeConfig: {
repo: 'Akryum/vue-cli-plugin-ssr',
docsDir: 'docs',
editLinks: true,
serviceWorker: {
updatePopup: true,
sidebar: {
'/guide/': [
'',
'configuration',
'directives',
'webpack',
],
},
locales: {
'/': {
selectText: 'Languages',
label: 'English',
lastUpdated: 'Last Updated',
nav: [
{
text: 'Guide',
link: '/guide/',
},
{
text: 'Patreon',
link: 'https://www.patreon.com/akryum',
},
],
sidebarDepth: 3,
sidebar: {
'/guide/': [
'',
'configuration',
'directives',
'webpack',
],
},
nav: [
{
text: 'Guide',
link: '/guide/',
},
},
{
text: 'Patreon',
link: 'https://www.patreon.com/akryum',
},
],
},
host: '127.0.0.1',
}

2 changes: 2 additions & 0 deletions docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module.exports = {
const cookieParser = require('cookie-parser')
app.use(cookieParser())
},
// Copy URL to system clipboard on start
copyUrlOnStart: true,
// Paths
distPath: path.resolve(__dirname, './dist'),
error500Html: null,
Expand Down
16 changes: 8 additions & 8 deletions generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const chalk = require('chalk')

module.exports = (api, options, rootOptions) => {
if (!api.hasPlugin('router')) {
throw new Error(`Please install router plugin with 'vue add router'.`)
throw new Error('Please install router plugin with \'vue add router\'.')
}

api.extendPackage({
Expand Down Expand Up @@ -42,16 +42,16 @@ module.exports = (api, options, rootOptions) => {
const file = getFile(api, './src/main.js')
if (file) {
let contents = fs.readFileSync(file, { encoding: 'utf8' })
contents = contents.replace(/import router from ('|")\.\/router(\.\w+)?('|")/, `import { createRouter } from $1./router$3`)
contents = contents.replace(/import store from ('|")\.\/store(\.\w+)?('|")/, `import { createStore } from $1./store$3`)
contents = contents.replace(/import ('|")\.\/registerServiceWorker('|")\n/, ``)
contents = contents.replace(/const apolloProvider = createProvider\(({(.|\s)*?})?\)\n/, ``)
contents = contents.replace(/import router from ('|")\.\/router(\.\w+)?('|")/, 'import { createRouter } from $1./router$3')
contents = contents.replace(/import store from ('|")\.\/store(\.\w+)?('|")/, 'import { createStore } from $1./store$3')
contents = contents.replace(/import ('|")\.\/registerServiceWorker('|")\n/, '')
contents = contents.replace(/const apolloProvider = createProvider\(({(.|\s)*?})?\)\n/, '')
contents = contents.replace(/new Vue\({((.|\s)*)}\)\.\$mount\(.*?\)/, `export async function createApp ({
beforeApp = () => {},
afterApp = () => {}
} = {}) {
const router = createRouter()
${templateOptions.vuex ? `const store = createStore()` : ''}
${templateOptions.vuex ? 'const store = createStore()' : ''}
${templateOptions.apollo ? `const apolloProvider = createProvider({
ssr: process.server,
})` : ''}
Expand Down Expand Up @@ -87,7 +87,7 @@ module.exports = (api, options, rootOptions) => {
let contents = fs.readFileSync(file, { encoding: 'utf8' })
contents = contents.replace(/export default new Router\({((.|\s)+)}\)/, `export function createRouter () {
return new Router({
${contents.includes('mode:') ? '' : `mode: 'history',`}$1})
${contents.includes('mode:') ? '' : 'mode: \'history\','}$1})
}`)
contents = contents.replace(/mode:\s*("|')(hash|abstract)("|'),/, '')
fs.writeFileSync(file, contents, { encoding: 'utf8' })
Expand Down Expand Up @@ -126,7 +126,7 @@ module.exports = (api, options, rootOptions) => {
contents = contents.replace(/export default app => {((.|\s)*)}/, `export default app => {$1
ssrMiddleware(app, { prodOnly: true })
}`)
contents = `import ssrMiddleware from '@akryum/vue-cli-plugin-ssr/lib/app'\n` + contents
contents = 'import ssrMiddleware from \'@akryum/vue-cli-plugin-ssr/lib/app\'\n' + contents
fs.writeFileSync(file, contents, { encoding: 'utf8' })
}

Expand Down
8 changes: 7 additions & 1 deletion generator/templates/default/src/entry-client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<%_ if (apollo) { _%>
import 'isomorphic-fetch'
<%_ } _%>
import { loadAsyncComponents } from '@akryum/vue-cli-plugin-ssr/client'
<%_ if (pwa) { _%>
import './registerServiceWorker'
Expand All @@ -14,13 +17,16 @@ createApp({

afterApp ({
app,
router,
<%_ if (vuex) { _%>
store,
<%_ } _%>
}) {
<%_ if (vuex) { _%>
store.replaceState(window.__INITIAL_STATE__)
<%_ } _%>
app.$mount('#app')
router.onReady(() => {
app.$mount('#app')
})
}
})
4 changes: 4 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ module.exports = (app, options) => {
? errorHtml = errorHtml.replace('<!--server-error-msg-->', errorMessage)
: errorHtml += errorMessage
}

if (config.onError) {
config.onError(err, res)
}
}

res.status(500).send(errorHtml)
Expand Down
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
skipRequests: req => req.originalUrl === '/graphql',
nodeExternalsWhitelist: [/\.css$/, /\?vue&type=style/],
extendServer: null,
copyUrlOnStart: true,
// Paths
distPath: null,
error500Html: null,
Expand Down
15 changes: 8 additions & 7 deletions lib/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const chalk = require('chalk')

const config = require('./config')

module.exports.setupDevServer = ({ server, templatePath, onUpdate }) => new Promise((resolve, reject) => {
module.exports.setupDevServer = ({ server, templatePath, onUpdate, webpackConfig }) => new Promise((resolve, reject) => {
const service = config.service
if (!service) {
reject(new Error('No cli-service available. Make sure you ran the command with `vue-cli-service`.'))
Expand All @@ -20,7 +20,7 @@ module.exports.setupDevServer = ({ server, templatePath, onUpdate }) => new Prom
}

const { getWebpackConfigs } = require('./webpack')
const [clientConfig, serverConfig] = getWebpackConfigs(service)
const [clientConfig, serverConfig] = getWebpackConfigs(service, webpackConfig)

let serverBundle
let template
Expand Down Expand Up @@ -116,17 +116,18 @@ module.exports.setupDevServer = ({ server, templatePath, onUpdate }) => new Prom
})

function onCompilationCompleted () {
copied = ''
if (firstRun) {
firstRun = false
require('clipboardy').write(url)
copied = chalk.dim('(copied to clipboard)')
} else {
copied = ''
if (config.copyUrlOnStart) {
require('clipboardy').write(url)
copied = chalk.dim('(copied to clipboard)')
}
}

setTimeout(() => {
console.log()
console.log(` App running at:`)
console.log(' App running at:')
console.log(` - Local: ${chalk.cyan(url)} ${copied}`)
})
}
Expand Down
14 changes: 7 additions & 7 deletions lib/loaders/css-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ module.exports.pitch = function (remainingRequest) {

if (isServer && isProduction) {
const shared = [
`// load the styles`,
'// load the styles',
`var content = require(${request});`,
// content list format is [id, css, media, sourceMap]
`if(typeof content === 'string') content = [[module.id, content, '']];`,
`module.exports = content;`,
`if(content.locals) module.exports = content.locals;`,
'if(typeof content === \'string\') content = [[module.id, content, \'\']];',
'module.exports = content;',
'if(content.locals) module.exports = content.locals;',
]
// on the server: attach to Vue SSR context
if (isVue) {
// inside *.vue file: expose a function so it can be called in
// component's lifecycle hooks
return shared.concat([
`// add CSS to SSR context`,
'// add CSS to SSR context',
`var add = require(${addStylesServerPath}).default`,
`module.exports.__inject__ = function (context) {`,
'module.exports.__inject__ = function (context) {',
` add(${id}, content, ${isProduction}, context)`,
`};`,
'};',
]).join('\n')
} else {
// normal import
Expand Down
1 change: 1 addition & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports.createServer = ({
port,
host,
}) => {
/* eslint-disable-next-line no-async-promise-executor */
return new Promise(async (resolve, reject) => {
const app = express()

Expand Down
10 changes: 6 additions & 4 deletions lib/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,26 @@ exports.chainWebpack = (webpackConfig) => {
// HTML
webpackConfig.plugin('html-filter').use(HtmlFilterPlugin)
if (isProd) {
// TODO Make customizable from outside
webpackConfig.plugin('html').tap(args => {
args[0].minify.removeComments = false
args[0].minify.caseSensitive = true
return args
})
}

webpackConfig.entry('app').clear().add(config.entry(target))

webpackConfig.plugin('define').tap(args => {
return [Object.assign(args[0], {'process.client': target === 'client', 'process.server': target === 'server'})]
return [Object.assign(args[0], { 'process.client': target === 'client', 'process.server': target === 'server' })]
})

webpackConfig.stats(isProd ? 'normal' : 'none')
webpackConfig.devServer.stats('errors-only').quiet(true).noInfo(true)

if (isClient) {
webpackConfig.plugin('ssr').use(VueSSRClientPlugin)
webpackConfig.plugin('loader').use(WebpackBar, [{name: 'Client', color: 'green'}])
webpackConfig.plugin('loader').use(WebpackBar, [{ name: 'Client', color: 'green' }])

webpackConfig.devtool(!isProd ? '#cheap-module-source-map' : undefined)

Expand All @@ -70,10 +72,10 @@ exports.chainWebpack = (webpackConfig) => {
})
} else {
webpackConfig.plugin('ssr').use(VueSSRServerPlugin)
webpackConfig.plugin('loader').use(WebpackBar, [{name: 'Server', color: 'orange'}])
webpackConfig.plugin('loader').use(WebpackBar, [{ name: 'Server', color: 'orange' }])

webpackConfig.devtool('source-map')
webpackConfig.externals(nodeExternals({whitelist: config.nodeExternalsWhitelist}))
webpackConfig.externals(nodeExternals({ whitelist: config.nodeExternalsWhitelist }))
webpackConfig.output.libraryTarget('commonjs2'); webpackConfig.target('node')
webpackConfig.optimization.splitChunks(false).minimize(false)

Expand Down
Loading