Add build.plugins and fix when no component matched

This commit is contained in:
Sébastien Chopin 2016-11-17 22:12:21 +01:00
parent 06edc8029b
commit 49f67566c2
5 changed files with 14 additions and 12 deletions

View File

@ -49,6 +49,7 @@ export default context => {
context.error = _app.error.bind(_app) context.error = _app.error.bind(_app)
<%= (isDev ? 'const s = isDev && Date.now()' : '') %> <%= (isDev ? 'const s = isDev && Date.now()' : '') %>
let Components = getMatchedComponents(context.route)
<% if (store) { %> <% if (store) { %>
let promise = (store._actions && store._actions.nuxtServerInit ? store.dispatch('nuxtServerInit', omit(getContext(context), 'redirect', 'error')) : null) let promise = (store._actions && store._actions.nuxtServerInit ? store.dispatch('nuxtServerInit', omit(getContext(context), 'redirect', 'error')) : null)
if (!(promise instanceof Promise)) promise = Promise.resolve() if (!(promise instanceof Promise)) promise = Promise.resolve()
@ -58,12 +59,6 @@ export default context => {
return promise return promise
.then(() => { .then(() => {
// Call data & fecth hooks on components matched by the route. // Call data & fecth hooks on components matched by the route.
let Components = getMatchedComponents(context.route)
if (!Components.length) {
context.nuxt.error = _app.error({ statusCode: 404, message: 'This page could not be found.', url: context.route.path })
<%= (store ? 'context.nuxt.state = store.state' : '') %>
return Promise.resolve(_app)
}
return Promise.all(Components.map((Component) => { return Promise.all(Components.map((Component) => {
let promises = [] let promises = []
if (!Component.options) { if (!Component.options) {
@ -89,6 +84,11 @@ export default context => {
})) }))
}) })
.then((res) => { .then((res) => {
if (!Components.length) {
context.nuxt.error = _app.error({ statusCode: 404, message: 'This page could not be found.', url: context.route.path })
<%= (store ? 'context.nuxt.state = store.state' : '') %>
return _app
}
<% if (isDev) { %> <% if (isDev) { %>
debug('Data fetching ' + context.req.url + ': ' + (Date.now() - s) + 'ms') debug('Data fetching ' + context.req.url + ': ' + (Date.now() - s) + 'ms')
<% } %> <% } %>

View File

@ -30,11 +30,12 @@ const defaults = {
app: 'nuxt.bundle.js' app: 'nuxt.bundle.js'
}, },
vendor: [], vendor: [],
loaders: [] loaders: [],
plugins: []
} }
const defaultsLoaders = [ const defaultsLoaders = [
{ {
test: /\.(png|jpg|gif|svg)$/, test: /\.(png|jpe?g|gif|svg)$/,
loader: 'url-loader', loader: 'url-loader',
query: { query: {
limit: 1000, // 1KO limit: 1000, // 1KO

View File

@ -61,7 +61,8 @@ module.exports = function () {
} }
} }
] ]
} },
plugins: this.options.build.plugins
} }
// Add nuxt build loaders (can be configured in nuxt.config.js) // Add nuxt build loaders (can be configured in nuxt.config.js)
config.module.rules = config.module.rules.concat(this.options.build.loaders) config.module.rules = config.module.rules.concat(this.options.build.loaders)

View File

@ -23,13 +23,13 @@ module.exports = function () {
filename: 'server-bundle.js', filename: 'server-bundle.js',
libraryTarget: 'commonjs2' libraryTarget: 'commonjs2'
}), }),
plugins: [ plugins: (config.plugins || []).concat([
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'), 'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'),
'process.env.VUE_ENV': '"server"', 'process.env.VUE_ENV': '"server"',
'process.BROWSER': false 'process.BROWSER': false
}) })
] ])
}) })
// Externals // Externals

View File

@ -1,6 +1,6 @@
{ {
"name": "nuxt", "name": "nuxt",
"version": "0.4.6", "version": "0.4.7",
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)", "description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)",
"main": "index.js", "main": "index.js",
"license": "MIT", "license": "MIT",