mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-05 11:57:13 +00:00
fix: lint error
This commit is contained in:
parent
83815de91b
commit
cc7c069985
@ -25,7 +25,7 @@ debug.color = 2 // Force green color
|
|||||||
const glob = pify(Glob)
|
const glob = pify(Glob)
|
||||||
|
|
||||||
export default class Builder extends Tapable {
|
export default class Builder extends Tapable {
|
||||||
constructor (nuxt) {
|
constructor(nuxt) {
|
||||||
super()
|
super()
|
||||||
this.nuxt = nuxt
|
this.nuxt = nuxt
|
||||||
this.isStatic = false // Flag to know if the build is for a generated app
|
this.isStatic = false // Flag to know if the build is for a generated app
|
||||||
@ -59,7 +59,7 @@ export default class Builder extends Tapable {
|
|||||||
this._buildStatus = STATUS.INITIAL
|
this._buildStatus = STATUS.INITIAL
|
||||||
}
|
}
|
||||||
|
|
||||||
get plugins () {
|
get plugins() {
|
||||||
return this.options.plugins.map((p, i) => {
|
return this.options.plugins.map((p, i) => {
|
||||||
if (typeof p === 'string') p = { src: p }
|
if (typeof p === 'string') p = { src: p }
|
||||||
return {
|
return {
|
||||||
@ -70,7 +70,7 @@ export default class Builder extends Tapable {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
vendor () {
|
vendor() {
|
||||||
return [
|
return [
|
||||||
'vue',
|
'vue',
|
||||||
'vue-router',
|
'vue-router',
|
||||||
@ -79,7 +79,7 @@ export default class Builder extends Tapable {
|
|||||||
].concat(this.options.build.vendor).filter(v => v)
|
].concat(this.options.build.vendor).filter(v => v)
|
||||||
}
|
}
|
||||||
|
|
||||||
vendorEntries () {
|
vendorEntries() {
|
||||||
// Used for dll
|
// Used for dll
|
||||||
const vendor = this.vendor()
|
const vendor = this.vendor()
|
||||||
const vendorEntries = {}
|
const vendorEntries = {}
|
||||||
@ -94,11 +94,11 @@ export default class Builder extends Tapable {
|
|||||||
return vendorEntries
|
return vendorEntries
|
||||||
}
|
}
|
||||||
|
|
||||||
forGenerate () {
|
forGenerate() {
|
||||||
this.isStatic = true
|
this.isStatic = true
|
||||||
}
|
}
|
||||||
|
|
||||||
async build () {
|
async build() {
|
||||||
// Avoid calling build() method multiple times when dev:true
|
// Avoid calling build() method multiple times when dev:true
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (this._buildStatus === STATUS.BUILD_DONE && this.options.dev) {
|
if (this._buildStatus === STATUS.BUILD_DONE && this.options.dev) {
|
||||||
@ -185,7 +185,7 @@ export default class Builder extends Tapable {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateRoutesAndFiles () {
|
async generateRoutesAndFiles() {
|
||||||
debug('Generating files...')
|
debug('Generating files...')
|
||||||
// -- Templates --
|
// -- Templates --
|
||||||
let templatesFiles = [
|
let templatesFiles = [
|
||||||
@ -375,7 +375,7 @@ export default class Builder extends Tapable {
|
|||||||
await this.applyPluginsAsync('generated', this)
|
await this.applyPluginsAsync('generated', this)
|
||||||
}
|
}
|
||||||
|
|
||||||
async webpackBuild () {
|
async webpackBuild() {
|
||||||
debug('Building files...')
|
debug('Building files...')
|
||||||
const compilersOptions = []
|
const compilersOptions = []
|
||||||
|
|
||||||
@ -484,7 +484,7 @@ export default class Builder extends Tapable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
webpackDev (compiler) {
|
webpackDev(compiler) {
|
||||||
debug('Adding webpack middleware...')
|
debug('Adding webpack middleware...')
|
||||||
|
|
||||||
// Create webpack dev middleware
|
// Create webpack dev middleware
|
||||||
@ -516,7 +516,7 @@ export default class Builder extends Tapable {
|
|||||||
this.watchFiles()
|
this.watchFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
watchFiles () {
|
watchFiles() {
|
||||||
const patterns = [
|
const patterns = [
|
||||||
r(this.options.srcDir, 'layouts'),
|
r(this.options.srcDir, 'layouts'),
|
||||||
r(this.options.srcDir, 'store'),
|
r(this.options.srcDir, 'store'),
|
||||||
|
@ -9,7 +9,7 @@ import Debug from 'debug'
|
|||||||
const debug = Debug('nuxt:generate')
|
const debug = Debug('nuxt:generate')
|
||||||
|
|
||||||
export default class Generator extends Tapable {
|
export default class Generator extends Tapable {
|
||||||
constructor (nuxt, builder) {
|
constructor(nuxt, builder) {
|
||||||
super()
|
super()
|
||||||
this.nuxt = nuxt
|
this.nuxt = nuxt
|
||||||
this.options = nuxt.options
|
this.options = nuxt.options
|
||||||
@ -22,7 +22,7 @@ export default class Generator extends Tapable {
|
|||||||
this.distNuxtPath = join(this.distPath, (isUrl(this.options.build.publicPath) ? '' : this.options.build.publicPath))
|
this.distNuxtPath = join(this.distPath, (isUrl(this.options.build.publicPath) ? '' : this.options.build.publicPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
async generate ({ build = true, init = true } = {}) {
|
async generate({ build = true, init = true } = {}) {
|
||||||
const s = Date.now()
|
const s = Date.now()
|
||||||
let errors = []
|
let errors = []
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ export default class Generator extends Tapable {
|
|||||||
return { duration, errors }
|
return { duration, errors }
|
||||||
}
|
}
|
||||||
|
|
||||||
async initDist () {
|
async initDist() {
|
||||||
// Clean destination folder
|
// Clean destination folder
|
||||||
await remove(this.distPath)
|
await remove(this.distPath)
|
||||||
debug('Destination folder cleaned')
|
debug('Destination folder cleaned')
|
||||||
@ -137,7 +137,7 @@ export default class Generator extends Tapable {
|
|||||||
debug('Static & build files copied')
|
debug('Static & build files copied')
|
||||||
}
|
}
|
||||||
|
|
||||||
decorateWithPayloads (routes, generateRoutes) {
|
decorateWithPayloads(routes, generateRoutes) {
|
||||||
let routeMap = {}
|
let routeMap = {}
|
||||||
// Fill routeMap for known routes
|
// Fill routeMap for known routes
|
||||||
routes.forEach((route) => {
|
routes.forEach((route) => {
|
||||||
@ -158,7 +158,7 @@ export default class Generator extends Tapable {
|
|||||||
return _.values(routeMap)
|
return _.values(routeMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateRoute ({ route, payload = {}, errors = [] }) {
|
async generateRoute({ route, payload = {}, errors = [] }) {
|
||||||
let html
|
let html
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export default function vueLoader () {
|
export default function vueLoader() {
|
||||||
// https://vue-loader.vuejs.org/en
|
// https://vue-loader.vuejs.org/en
|
||||||
const config = {
|
const config = {
|
||||||
postcss: this.options.build.postcss,
|
postcss: this.options.build.postcss,
|
||||||
|
@ -9,19 +9,19 @@ import Debug from 'debug'
|
|||||||
const debug = Debug('nuxt:module')
|
const debug = Debug('nuxt:module')
|
||||||
|
|
||||||
export default class ModuleContainer extends Tapable {
|
export default class ModuleContainer extends Tapable {
|
||||||
constructor (nuxt) {
|
constructor(nuxt) {
|
||||||
super()
|
super()
|
||||||
this.nuxt = nuxt
|
this.nuxt = nuxt
|
||||||
this.options = nuxt.options
|
this.options = nuxt.options
|
||||||
this.requiredModules = []
|
this.requiredModules = []
|
||||||
}
|
}
|
||||||
|
|
||||||
async _ready () {
|
async _ready() {
|
||||||
await sequence(this.options.modules, this.addModule.bind(this))
|
await sequence(this.options.modules, this.addModule.bind(this))
|
||||||
await this.applyPluginsAsync('ready', this)
|
await this.applyPluginsAsync('ready', this)
|
||||||
}
|
}
|
||||||
|
|
||||||
addVendor (vendor) {
|
addVendor(vendor) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!vendor) {
|
if (!vendor) {
|
||||||
return
|
return
|
||||||
@ -29,7 +29,7 @@ export default class ModuleContainer extends Tapable {
|
|||||||
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
|
||||||
@ -56,7 +56,7 @@ export default class ModuleContainer extends Tapable {
|
|||||||
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.unshift({
|
this.options.plugins.unshift({
|
||||||
@ -65,24 +65,24 @@ export default class ModuleContainer extends Tapable {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
async addModule (moduleOpts, requireOnce) {
|
async addModule(moduleOpts, requireOnce) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!moduleOpts) {
|
if (!moduleOpts) {
|
||||||
return
|
return
|
||||||
|
@ -12,7 +12,7 @@ const debug = Debug('nuxt:')
|
|||||||
debug.color = 5
|
debug.color = 5
|
||||||
|
|
||||||
export default class Nuxt extends Tapable {
|
export default class Nuxt extends Tapable {
|
||||||
constructor (_options = {}) {
|
constructor(_options = {}) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this.options = Options.from(_options)
|
this.options = Options.from(_options)
|
||||||
@ -35,7 +35,7 @@ export default class Nuxt extends Tapable {
|
|||||||
this._ready = this.ready().catch(this.errorHandler)
|
this._ready = this.ready().catch(this.errorHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
async ready () {
|
async ready() {
|
||||||
if (this._ready) {
|
if (this._ready) {
|
||||||
return this._ready
|
return this._ready
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ export default class Nuxt extends Tapable {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
listen (port = 3000, host = 'localhost') {
|
listen(port = 3000, host = 'localhost') {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const server = this.renderer.app.listen({ port, host, exclusive: false }, err => {
|
const server = this.renderer.app.listen({ port, host, exclusive: false }, err => {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
@ -81,7 +81,7 @@ export default class Nuxt extends Tapable {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
errorHandler /* istanbul ignore next */() {
|
errorHandler() {
|
||||||
// Apply plugins
|
// Apply plugins
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
this.applyPluginsAsync('error', ...arguments).catch(console.error)
|
this.applyPluginsAsync('error', ...arguments).catch(console.error)
|
||||||
@ -101,7 +101,7 @@ export default class Nuxt extends Tapable {
|
|||||||
console.error(...arguments)
|
console.error(...arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
resolvePath (path) {
|
resolvePath(path) {
|
||||||
// Try to resolve using NPM resolve path first
|
// Try to resolve using NPM resolve path first
|
||||||
try {
|
try {
|
||||||
let resolvedPath = Module._resolveFilename(path, { paths: this.nodeModulePaths })
|
let resolvedPath = Module._resolveFilename(path, { paths: this.nodeModulePaths })
|
||||||
@ -118,7 +118,7 @@ export default class Nuxt extends Tapable {
|
|||||||
return resolve(this.options.srcDir, path)
|
return resolve(this.options.srcDir, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
async close (callback) {
|
async close(callback) {
|
||||||
await this.applyPluginsAsync('close')
|
await this.applyPluginsAsync('close')
|
||||||
|
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
|
@ -25,7 +25,7 @@ setAnsiColors(ansiHTML)
|
|||||||
let jsdom = null
|
let jsdom = null
|
||||||
|
|
||||||
export default class Renderer extends Tapable {
|
export default class Renderer extends Tapable {
|
||||||
constructor (nuxt) {
|
constructor(nuxt) {
|
||||||
super()
|
super()
|
||||||
this.nuxt = nuxt
|
this.nuxt = nuxt
|
||||||
this.options = nuxt.options
|
this.options = nuxt.options
|
||||||
@ -51,7 +51,7 @@ export default class Renderer extends Tapable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _ready () {
|
async _ready() {
|
||||||
await this.nuxt.applyPluginsAsync('renderer', this)
|
await this.nuxt.applyPluginsAsync('renderer', this)
|
||||||
|
|
||||||
// Setup nuxt middleware
|
// Setup nuxt middleware
|
||||||
@ -66,7 +66,7 @@ export default class Renderer extends Tapable {
|
|||||||
await this.applyPluginsAsync('ready', this)
|
await this.applyPluginsAsync('ready', this)
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadResources (_fs = fs) {
|
async loadResources(_fs = fs) {
|
||||||
let distPath = resolve(this.options.buildDir, 'dist')
|
let distPath = resolve(this.options.buildDir, 'dist')
|
||||||
let updated = []
|
let updated = []
|
||||||
|
|
||||||
@ -115,11 +115,11 @@ export default class Renderer extends Tapable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get noSSR () {
|
get noSSR() {
|
||||||
return this.options.render.ssr === false
|
return this.options.render.ssr === false
|
||||||
}
|
}
|
||||||
|
|
||||||
get isReady () {
|
get isReady() {
|
||||||
if (this.noSSR) {
|
if (this.noSSR) {
|
||||||
return Boolean(this.resources.spaTemplate)
|
return Boolean(this.resources.spaTemplate)
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ export default class Renderer extends Tapable {
|
|||||||
return Boolean(this.bundleRenderer && this.resources.ssrTemplate)
|
return Boolean(this.bundleRenderer && this.resources.ssrTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
get isResourcesAvailable () {
|
get isResourcesAvailable() {
|
||||||
// Required for both
|
// Required for both
|
||||||
if (!this.resources.clientManifest) {
|
if (!this.resources.clientManifest) {
|
||||||
return false
|
return false
|
||||||
@ -142,7 +142,7 @@ export default class Renderer extends Tapable {
|
|||||||
return Boolean(this.resources.ssrTemplate && this.resources.serverBundle)
|
return Boolean(this.resources.ssrTemplate && this.resources.serverBundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
createRenderer () {
|
createRenderer() {
|
||||||
// Ensure resources are available
|
// Ensure resources are available
|
||||||
if (!this.isResourcesAvailable) {
|
if (!this.isResourcesAvailable) {
|
||||||
return
|
return
|
||||||
@ -164,7 +164,7 @@ export default class Renderer extends Tapable {
|
|||||||
}, this.options.render.bundleRenderer))
|
}, this.options.render.bundleRenderer))
|
||||||
}
|
}
|
||||||
|
|
||||||
useMiddleware (m) {
|
useMiddleware(m) {
|
||||||
// Resolve
|
// Resolve
|
||||||
const $m = m
|
const $m = m
|
||||||
let src
|
let src
|
||||||
@ -188,11 +188,11 @@ export default class Renderer extends Tapable {
|
|||||||
this.app.use(path, handler)
|
this.app.use(path, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
get publicPath () {
|
get publicPath() {
|
||||||
return isUrl(this.options.build.publicPath) ? Options.defaults.build.publicPath : this.options.build.publicPath
|
return isUrl(this.options.build.publicPath) ? Options.defaults.build.publicPath : this.options.build.publicPath
|
||||||
}
|
}
|
||||||
|
|
||||||
async setupMiddleware () {
|
async setupMiddleware() {
|
||||||
// Apply setupMiddleware from modules first
|
// Apply setupMiddleware from modules first
|
||||||
await this.applyPluginsAsync('setupMiddleware', this.app)
|
await this.applyPluginsAsync('setupMiddleware', this.app)
|
||||||
|
|
||||||
@ -229,7 +229,7 @@ export default class Renderer extends Tapable {
|
|||||||
if (this.options.debug) {
|
if (this.options.debug) {
|
||||||
this.useMiddleware({
|
this.useMiddleware({
|
||||||
path: '_open',
|
path: '_open',
|
||||||
handler (req, res) {
|
handler(req, res) {
|
||||||
// Lazy load open-in-editor
|
// Lazy load open-in-editor
|
||||||
const openInEditor = require('open-in-editor')
|
const openInEditor = require('open-in-editor')
|
||||||
const editor = openInEditor.configure(_this.options.editor)
|
const editor = openInEditor.configure(_this.options.editor)
|
||||||
@ -280,7 +280,7 @@ export default class Renderer extends Tapable {
|
|||||||
this.useMiddleware(this.errorMiddleware.bind(this))
|
this.useMiddleware(this.errorMiddleware.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
async nuxtMiddleware (req, res, next) {
|
async nuxtMiddleware(req, res, next) {
|
||||||
// Get context
|
// Get context
|
||||||
const context = getContext(req, res)
|
const context = getContext(req, res)
|
||||||
res.statusCode = 200
|
res.statusCode = 200
|
||||||
@ -338,7 +338,7 @@ export default class Renderer extends Tapable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
errorMiddleware (err, req, res, next) {
|
errorMiddleware(err, req, res, next) {
|
||||||
// ensure statusCode, message and name fields
|
// ensure statusCode, message and name fields
|
||||||
err.statusCode = err.statusCode || 500
|
err.statusCode = err.statusCode || 500
|
||||||
err.message = err.message || 'Nuxt Server Error'
|
err.message = err.message || 'Nuxt Server Error'
|
||||||
@ -390,7 +390,7 @@ export default class Renderer extends Tapable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async readSource (frame) {
|
async readSource(frame) {
|
||||||
const serverBundle = this.resources.serverBundle
|
const serverBundle = this.resources.serverBundle
|
||||||
|
|
||||||
// Remove webpack:/// & query string from the end
|
// Remove webpack:/// & query string from the end
|
||||||
@ -468,7 +468,7 @@ export default class Renderer extends Tapable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderRoute (url, context = {}) {
|
async renderRoute(url, context = {}) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!this.isReady) {
|
if (!this.isReady) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
@ -546,7 +546,7 @@ export default class Renderer extends Tapable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderAndGetWindow (url, opts = {}) {
|
async renderAndGetWindow(url, opts = {}) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!jsdom) {
|
if (!jsdom) {
|
||||||
try {
|
try {
|
||||||
@ -561,7 +561,7 @@ export default class Renderer extends Tapable {
|
|||||||
let options = {
|
let options = {
|
||||||
resources: 'usable', // load subresources (https://github.com/tmpvar/jsdom#loading-subresources)
|
resources: 'usable', // load subresources (https://github.com/tmpvar/jsdom#loading-subresources)
|
||||||
runScripts: 'dangerously',
|
runScripts: 'dangerously',
|
||||||
beforeParse (window) {
|
beforeParse(window) {
|
||||||
// Mock window.scrollTo
|
// Mock window.scrollTo
|
||||||
window.scrollTo = () => {
|
window.scrollTo = () => {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user