mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
chore: eslint
This commit is contained in:
parent
bd54ddd2a7
commit
b37c7cbd8d
@ -2,21 +2,21 @@
|
|||||||
|
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import {uniq} from 'lodash'
|
import { uniq } from 'lodash'
|
||||||
import hash from 'hash-sum'
|
import hash from 'hash-sum'
|
||||||
import {chainFn, sequence} from './utils'
|
import { chainFn, sequence } from './utils'
|
||||||
|
|
||||||
const debug = require('debug')('nuxt:module')
|
const debug = require('debug')('nuxt:module')
|
||||||
|
|
||||||
class Module {
|
class Module {
|
||||||
constructor(nuxt) {
|
constructor (nuxt) {
|
||||||
this.nuxt = nuxt
|
this.nuxt = nuxt
|
||||||
this.options = nuxt.options
|
this.options = nuxt.options
|
||||||
this.requiredModules = []
|
this.requiredModules = []
|
||||||
this.initing = this.ready()
|
this.initing = this.ready()
|
||||||
}
|
}
|
||||||
|
|
||||||
async ready() {
|
async ready () {
|
||||||
if (this.initing) {
|
if (this.initing) {
|
||||||
await this.initing
|
await this.initing
|
||||||
return this
|
return this
|
||||||
@ -26,7 +26,7 @@ class Module {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
addVendor(vendor) {
|
addVendor (vendor) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!vendor) {
|
if (!vendor) {
|
||||||
return
|
return
|
||||||
@ -34,7 +34,7 @@ class Module {
|
|||||||
this.options.build.vendor = uniq(this.options.build.vendor.concat(vendor))
|
this.options.build.vendor = uniq(this.options.build.vendor.concat(vendor))
|
||||||
}
|
}
|
||||||
|
|
||||||
addTemplate(template) {
|
addTemplate (template) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!template) {
|
if (!template) {
|
||||||
return
|
return
|
||||||
@ -60,7 +60,7 @@ class Module {
|
|||||||
return templateObj
|
return templateObj
|
||||||
}
|
}
|
||||||
|
|
||||||
addPlugin(template) {
|
addPlugin (template) {
|
||||||
const {dst} = this.addTemplate(template)
|
const {dst} = this.addTemplate(template)
|
||||||
// Add to nuxt plugins
|
// Add to nuxt plugins
|
||||||
this.options.plugins.push({
|
this.options.plugins.push({
|
||||||
@ -69,24 +69,24 @@ class Module {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
addServerMiddleware(middleware) {
|
addServerMiddleware (middleware) {
|
||||||
this.options.serverMiddleware.push(middleware)
|
this.options.serverMiddleware.push(middleware)
|
||||||
}
|
}
|
||||||
|
|
||||||
extendBuild(fn) {
|
extendBuild (fn) {
|
||||||
this.options.build.extend = chainFn(this.options.build.extend, fn)
|
this.options.build.extend = chainFn(this.options.build.extend, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
extendRoutes(fn) {
|
extendRoutes (fn) {
|
||||||
this.options.router.extendRoutes = chainFn(this.options.router.extendRoutes, fn)
|
this.options.router.extendRoutes = chainFn(this.options.router.extendRoutes, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
requireModule(moduleOpts) {
|
requireModule (moduleOpts) {
|
||||||
// Require once
|
// Require once
|
||||||
return this.addModule(moduleOpts, true)
|
return this.addModule(moduleOpts, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
addModule(moduleOpts, requireOnce) {
|
addModule (moduleOpts, requireOnce) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!moduleOpts) {
|
if (!moduleOpts) {
|
||||||
return
|
return
|
||||||
|
@ -5,6 +5,7 @@ import serialize from 'serialize-javascript'
|
|||||||
import generateETag from 'etag'
|
import generateETag from 'etag'
|
||||||
import fresh from 'fresh'
|
import fresh from 'fresh'
|
||||||
import { getContext, setAnsiColors, encodeHtml } from './utils'
|
import { getContext, setAnsiColors, encodeHtml } from './utils'
|
||||||
|
|
||||||
const debug = require('debug')('nuxt:render')
|
const debug = require('debug')('nuxt:render')
|
||||||
// force blue color
|
// force blue color
|
||||||
debug.color = 4
|
debug.color = 4
|
||||||
@ -57,7 +58,7 @@ export async function render (req, res) {
|
|||||||
res.statusCode = 404
|
res.statusCode = 404
|
||||||
return res.end()
|
return res.end()
|
||||||
}
|
}
|
||||||
const { html, error, redirected, resourceHints } = await this.renderRoute(req.url, context)
|
const {html, error, redirected, resourceHints} = await this.renderRoute(req.url, context)
|
||||||
if (redirected) {
|
if (redirected) {
|
||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
@ -67,7 +68,7 @@ export async function render (req, res) {
|
|||||||
// ETag header
|
// ETag header
|
||||||
if (!error && this.options.render.etag) {
|
if (!error && this.options.render.etag) {
|
||||||
const etag = generateETag(html, this.options.render.etag)
|
const etag = generateETag(html, this.options.render.etag)
|
||||||
if (fresh(req.headers, { etag })) {
|
if (fresh(req.headers, {etag})) {
|
||||||
res.statusCode = 304
|
res.statusCode = 304
|
||||||
res.end()
|
res.end()
|
||||||
return
|
return
|
||||||
@ -75,7 +76,7 @@ export async function render (req, res) {
|
|||||||
res.setHeader('ETag', etag)
|
res.setHeader('ETag', etag)
|
||||||
}
|
}
|
||||||
// HTTP2 push headers
|
// HTTP2 push headers
|
||||||
if(!error && this.options.render.http2.push) {
|
if (!error && this.options.render.http2.push) {
|
||||||
// Parse resourceHints to extract HTTP.2 prefetch/push headers
|
// Parse resourceHints to extract HTTP.2 prefetch/push headers
|
||||||
// https://w3c.github.io/preload/#server-push-http-2
|
// https://w3c.github.io/preload/#server-push-http-2
|
||||||
const regex = /link rel="([^"]*)" href="([^"]*)" as="([^"]*)"/g
|
const regex = /link rel="([^"]*)" href="([^"]*)" as="([^"]*)"/g
|
||||||
@ -101,7 +102,7 @@ export async function render (req, res) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
const html = this.errorTemplate({
|
const html = this.errorTemplate({
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
error: err,
|
error: err,
|
||||||
stack: ansiHTML(encodeHtml(err.stack))
|
stack: ansiHTML(encodeHtml(err.stack))
|
||||||
})
|
})
|
||||||
@ -133,7 +134,7 @@ export async function renderRoute (url, context = {}) {
|
|||||||
}
|
}
|
||||||
const resourceHints = context.renderResourceHints()
|
const resourceHints = context.renderResourceHints()
|
||||||
HEAD += resourceHints + context.renderStyles()
|
HEAD += resourceHints + context.renderStyles()
|
||||||
APP += `<script type="text/javascript">window.__NUXT__=${serialize(context.nuxt, { isJSON: true })}</script>`
|
APP += `<script type="text/javascript">window.__NUXT__=${serialize(context.nuxt, {isJSON: true})}</script>`
|
||||||
APP += context.renderScripts()
|
APP += context.renderScripts()
|
||||||
const html = this.appTemplate({
|
const html = this.appTemplate({
|
||||||
HTML_ATTRS: 'data-n-head-ssr ' + m.htmlAttrs.text(),
|
HTML_ATTRS: 'data-n-head-ssr ' + m.htmlAttrs.text(),
|
||||||
@ -168,14 +169,15 @@ export async function renderAndGetWindow (url, opts = {}) {
|
|||||||
runScripts: 'dangerously',
|
runScripts: 'dangerously',
|
||||||
beforeParse (window) {
|
beforeParse (window) {
|
||||||
// Mock window.scrollTo
|
// Mock window.scrollTo
|
||||||
window.scrollTo = () => {}
|
window.scrollTo = () => {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (opts.virtualConsole !== false) {
|
if (opts.virtualConsole !== false) {
|
||||||
options.virtualConsole = new jsdom.VirtualConsole().sendTo(console)
|
options.virtualConsole = new jsdom.VirtualConsole().sendTo(console)
|
||||||
}
|
}
|
||||||
url = url || 'http://localhost:3000'
|
url = url || 'http://localhost:3000'
|
||||||
const { window } = await jsdom.JSDOM.fromURL(url, options)
|
const {window} = await jsdom.JSDOM.fromURL(url, options)
|
||||||
// If Nuxt could not be loaded (error from the server-side)
|
// If Nuxt could not be loaded (error from the server-side)
|
||||||
const nuxtExists = window.document.body.innerHTML.includes('window.__NUXT__')
|
const nuxtExists = window.document.body.innerHTML.includes('window.__NUXT__')
|
||||||
if (!nuxtExists) {
|
if (!nuxtExists) {
|
||||||
|
Loading…
Reference in New Issue
Block a user