mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
Merge branch 'dev' of github.com:nuxt/nuxt.js into dev
This commit is contained in:
commit
1eca064338
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="progress" :style="{
|
<div class="nuxt-progress" :style="{
|
||||||
'width': percent+'%',
|
'width': percent+'%',
|
||||||
'height': height,
|
'height': height,
|
||||||
'background-color': canSuccess? color : failedColor,
|
'background-color': canSuccess? color : failedColor,
|
||||||
@ -87,8 +87,8 @@ export default {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style>
|
||||||
.progress {
|
.nuxt-progress {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0px;
|
top: 0px;
|
||||||
left: <%= loading.rtl === true ? 'auto' : '0px' %>;
|
left: <%= loading.rtl === true ? 'auto' : '0px' %>;
|
||||||
|
@ -518,7 +518,7 @@ export default class Builder extends Tapable {
|
|||||||
|
|
||||||
this.webpackHotMiddleware = pify(webpackHotMiddleware(this.compiler.client, Object.assign({
|
this.webpackHotMiddleware = pify(webpackHotMiddleware(this.compiler.client, Object.assign({
|
||||||
log: false,
|
log: false,
|
||||||
heartbeat: 2500
|
heartbeat: 1000
|
||||||
}, this.options.build.hotMiddleware)))
|
}, this.options.build.hotMiddleware)))
|
||||||
|
|
||||||
// Inject to renderer instance
|
// Inject to renderer instance
|
||||||
|
@ -151,7 +151,11 @@ export default function webpackClientConfig () {
|
|||||||
config.plugins.push(new webpack.NamedModulesPlugin())
|
config.plugins.push(new webpack.NamedModulesPlugin())
|
||||||
|
|
||||||
// Add HMR support
|
// Add HMR support
|
||||||
config.entry.app = ['webpack-hot-middleware/client?name=client&reload=true', config.entry.app]
|
config.entry.app = [
|
||||||
|
// https://github.com/glenjamin/webpack-hot-middleware#config
|
||||||
|
`webpack-hot-middleware/client?name=client&reload=true&timeout=3000&path=${this.options.router.base}/__webpack_hmr`.replace(/\/\//g, '/'),
|
||||||
|
config.entry.app
|
||||||
|
]
|
||||||
config.plugins.push(
|
config.plugins.push(
|
||||||
new webpack.HotModuleReplacementPlugin(),
|
new webpack.HotModuleReplacementPlugin(),
|
||||||
new webpack.NoEmitOnErrorsPlugin()
|
new webpack.NoEmitOnErrorsPlugin()
|
||||||
|
@ -96,7 +96,7 @@ export function isPureObject (o) {
|
|||||||
|
|
||||||
export const isWindows = /^win/.test(process.platform)
|
export const isWindows = /^win/.test(process.platform)
|
||||||
|
|
||||||
export function wp (p) {
|
export function wp (p = '') {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
return p.replace(/\\/g, '\\\\')
|
return p.replace(/\\/g, '\\\\')
|
||||||
@ -104,7 +104,7 @@ export function wp (p) {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
export function wChunk (p) {
|
export function wChunk (p = '') {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
return p.replace(/\//g, '\\\\')
|
return p.replace(/\//g, '\\\\')
|
||||||
|
@ -171,19 +171,26 @@ export default class Renderer extends Tapable {
|
|||||||
|
|
||||||
useMiddleware (m) {
|
useMiddleware (m) {
|
||||||
// Resolve
|
// Resolve
|
||||||
|
const $m = m
|
||||||
|
let src
|
||||||
if (typeof m === 'string') {
|
if (typeof m === 'string') {
|
||||||
m = require(this.nuxt.resolvePath(m))
|
src = this.nuxt.resolvePath(m)
|
||||||
|
m = require(src)
|
||||||
}
|
}
|
||||||
// Handler
|
if (typeof m.handler === 'string') {
|
||||||
if (m && typeof m.handler === 'string') {
|
src = this.nuxt.resolvePath(m.handler)
|
||||||
m.handler = require(this.nuxt.resolvePath(m.handler))
|
m.handler = require(src)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handler = m.handler || m
|
||||||
|
const path = (this.options.router.base + (m.path ? m.path : '')).replace(/\/\//g, '/')
|
||||||
|
|
||||||
|
// Inject $src and $m to final handler
|
||||||
|
if (src) handler.$src = src
|
||||||
|
handler.$m = $m
|
||||||
|
|
||||||
// Use middleware
|
// Use middleware
|
||||||
if (m instanceof Function) {
|
this.app.use(path, handler)
|
||||||
this.app.use(m)
|
|
||||||
} else if (m && m.path && m.handler) {
|
|
||||||
this.app.use(m.path, m.handler)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async setupMiddleware () {
|
async setupMiddleware () {
|
||||||
@ -197,10 +204,6 @@ export default class Renderer extends Tapable {
|
|||||||
|
|
||||||
// Common URL checks
|
// Common URL checks
|
||||||
this.useMiddleware((req, res, next) => {
|
this.useMiddleware((req, res, next) => {
|
||||||
// If base in req.url, remove it for the middleware and vue-router
|
|
||||||
if (this.options.router.base !== '/' && req.url.indexOf(this.options.router.base) === 0) {
|
|
||||||
req.url = req.url.replace(this.options.router.base, '/')
|
|
||||||
}
|
|
||||||
// Prevent access to SSR resources
|
// Prevent access to SSR resources
|
||||||
if (ssrResourceRegex.test(req.url)) {
|
if (ssrResourceRegex.test(req.url)) {
|
||||||
res.statusCode = 404
|
res.statusCode = 404
|
||||||
|
@ -90,11 +90,16 @@ test('Check stats.json generated by build.analyze', t => {
|
|||||||
t.is(stats.assets.length, 28)
|
t.is(stats.assets.length, 28)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Check /test.txt with custom serve-static options', async t => {
|
test('Check /test/test.txt with custom serve-static options', async t => {
|
||||||
const { headers } = await rp(url('/test.txt'), { resolveWithFullResponse: true })
|
const { headers } = await rp(url('/test/test.txt'), { resolveWithFullResponse: true })
|
||||||
t.is(headers['cache-control'], 'public, max-age=31536000')
|
t.is(headers['cache-control'], 'public, max-age=31536000')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Check /test.txt should return 404', async t => {
|
||||||
|
const err = await t.throws(rp(url('/test.txt')))
|
||||||
|
t.is(err.response.statusCode, 404)
|
||||||
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test.after('Closing server and nuxt.js', t => {
|
test.after('Closing server and nuxt.js', t => {
|
||||||
nuxt.close()
|
nuxt.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user