mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix: remove require.cache deletion
This commit is contained in:
parent
39ef28ca2a
commit
a74f206189
@ -11,7 +11,7 @@ const webpackDevMiddleware = require('webpack-dev-middleware')
|
|||||||
const webpackHotMiddleware = require('webpack-hot-middleware')
|
const webpackHotMiddleware = require('webpack-hot-middleware')
|
||||||
const Debug = require('debug')
|
const Debug = require('debug')
|
||||||
const Glob = require('glob')
|
const Glob = require('glob')
|
||||||
const { r, wp, wChunk, createRoutes, sequence, relativeTo, waitFor, rmCache } = require('../common/utils')
|
const { r, wp, wChunk, createRoutes, sequence, relativeTo, waitFor } = require('../common/utils')
|
||||||
const { Options } = require('../common')
|
const { Options } = require('../common')
|
||||||
const clientWebpackConfig = require('./webpack/client.config.js')
|
const clientWebpackConfig = require('./webpack/client.config.js')
|
||||||
const serverWebpackConfig = require('./webpack/server.config.js')
|
const serverWebpackConfig = require('./webpack/server.config.js')
|
||||||
@ -465,12 +465,6 @@ module.exports = class Builder {
|
|||||||
compiler.watch(this.options.watchers.webpack, (err) => {
|
compiler.watch(this.options.watchers.webpack, (err) => {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (err) return reject(err)
|
if (err) return reject(err)
|
||||||
// not keep modified or deleted items in Vue.prototype
|
|
||||||
Object.keys(require.cache).forEach(key => {
|
|
||||||
if (!/(node_modules\/postcss)|(\.node$)/.test(key)) {
|
|
||||||
rmCache(key)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
@ -268,16 +268,3 @@ exports.createRoutes = function createRoutes(files, srcDir) {
|
|||||||
})
|
})
|
||||||
return cleanChildrenRoutes(routes)
|
return cleanChildrenRoutes(routes)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.rmCache = function rmCache(path) {
|
|
||||||
const mod = require.cache[path]
|
|
||||||
delete require.cache[path]
|
|
||||||
if (mod.parent && mod.parent.children) {
|
|
||||||
for (let i = 0; i < mod.parent.children.length; i++) {
|
|
||||||
if (mod.parent.children[i] === mod) {
|
|
||||||
mod.parent.children.splice(i, 1)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import { intercept, release } from './helpers/console'
|
import { intercept, release } from './helpers/console'
|
||||||
import { Nuxt, Builder, Utils } from '..'
|
import { Nuxt, Builder } from '..'
|
||||||
import { truncateSync, readFileSync, writeFileSync } from 'fs'
|
|
||||||
|
|
||||||
const port = 4001
|
const port = 4001
|
||||||
const url = (route) => 'http://localhost:' + port + route
|
const url = (route) => 'http://localhost:' + port + route
|
||||||
const rootDir = resolve(__dirname, 'fixtures/basic')
|
const rootDir = resolve(__dirname, 'fixtures/basic')
|
||||||
const pluginPath = resolve(rootDir, 'plugins', 'watch.js')
|
|
||||||
const pluginContent = readFileSync(pluginPath)
|
|
||||||
|
|
||||||
let nuxt = null
|
let nuxt = null
|
||||||
|
|
||||||
@ -24,10 +21,7 @@ test.serial('Init Nuxt.js', async t => {
|
|||||||
extractCSS: {
|
extractCSS: {
|
||||||
allChunks: true
|
allChunks: true
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
plugins: [
|
|
||||||
'~/plugins/watch.js'
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const spies = await intercept({ log: true, stderr: true }, async () => {
|
const spies = await intercept({ log: true, stderr: true }, async () => {
|
||||||
@ -49,31 +43,6 @@ test.serial('Init Nuxt.js', async t => {
|
|||||||
// t.is(window.getComputedStyle(window.document.body).getPropertyValue('font-size'), '30px')
|
// t.is(window.getComputedStyle(window.document.body).getPropertyValue('font-size'), '30px')
|
||||||
// })
|
// })
|
||||||
|
|
||||||
test.serial('remove mixins in live reloading', async t => {
|
|
||||||
const spies = await intercept({ log: true, error: true, stderr: true })
|
|
||||||
await nuxt.renderRoute(url('/'))
|
|
||||||
t.true(spies.log.calledWith('I am mixin'))
|
|
||||||
|
|
||||||
truncateSync(pluginPath)
|
|
||||||
await new Promise(async (resolve, reject) => {
|
|
||||||
let waitTimes = 0
|
|
||||||
while (spies.log.neverCalledWithMatch(/Compiled successfully/)) {
|
|
||||||
if (waitTimes++ >= 20) {
|
|
||||||
t.fail('Dev server doesn\'t reload after 2000ms')
|
|
||||||
reject(Error())
|
|
||||||
}
|
|
||||||
await Utils.waitFor(100)
|
|
||||||
}
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
spies.log.reset()
|
|
||||||
|
|
||||||
await nuxt.renderRoute(url('/'))
|
|
||||||
t.true(spies.log.neverCalledWith('I am mixin'))
|
|
||||||
t.is(spies.error.getCall(0).args[0].statusCode, 404)
|
|
||||||
release()
|
|
||||||
})
|
|
||||||
|
|
||||||
test.serial('/stateless', async t => {
|
test.serial('/stateless', async t => {
|
||||||
const spies = await intercept()
|
const spies = await intercept()
|
||||||
const window = await nuxt.renderAndGetWindow(url('/stateless'))
|
const window = await nuxt.renderAndGetWindow(url('/stateless'))
|
||||||
@ -94,6 +63,5 @@ test.serial('/stateless', async t => {
|
|||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test.after.always('Closing server and nuxt.js', async t => {
|
test.after.always('Closing server and nuxt.js', async t => {
|
||||||
writeFileSync(pluginPath, pluginContent)
|
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
|
12
test/fixtures/basic/plugins/watch.js
vendored
12
test/fixtures/basic/plugins/watch.js
vendored
@ -1,12 +0,0 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
|
|
||||||
const Plugin = {
|
|
||||||
install(Vue) {
|
|
||||||
Vue.mixin({
|
|
||||||
created() {
|
|
||||||
console.log('I am mixin') // eslint-disable-line no-console
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Vue.use(Plugin)
|
|
Loading…
Reference in New Issue
Block a user