mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix: memory leak when frequent rebuild in watch mode
This commit is contained in:
parent
0b9cd1b408
commit
29df01f16e
@ -9,7 +9,7 @@ import { join, resolve, basename, extname, dirname } from 'path'
|
||||
import MFS from 'memory-fs'
|
||||
import webpackDevMiddleware from 'webpack-dev-middleware'
|
||||
import webpackHotMiddleware from 'webpack-hot-middleware'
|
||||
import { r, wp, wChunk, createRoutes, sequence, relativeTo, isPureObject, waitFor } from 'utils'
|
||||
import { r, wp, wChunk, createRoutes, sequence, relativeTo, isPureObject, waitFor, rmCache } from 'utils'
|
||||
import Debug from 'debug'
|
||||
import Glob from 'glob'
|
||||
import clientWebpackConfig from './webpack/client.config.js'
|
||||
@ -475,7 +475,11 @@ export default class Builder {
|
||||
/* istanbul ignore if */
|
||||
if (err) return reject(err)
|
||||
// not keep modified or deleted items in Vue.prototype
|
||||
Object.keys(require.cache).forEach(key => !/\.node$/.test(key) && delete require.cache[key])
|
||||
Object.keys(require.cache).forEach(key => {
|
||||
if (!/(node_modules\/postcss)|(\.node$)/.test(key)) {
|
||||
rmCache(key)
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
return
|
||||
|
@ -19,7 +19,7 @@ export default function webpackBaseConfig({ name, isServer }) {
|
||||
|
||||
const config = {
|
||||
name,
|
||||
devtool: this.options.dev ? 'cheap-module-source-map' : false,
|
||||
devtool: this.options.dev ? 'cheap-module-eval-source-map' : false,
|
||||
entry: {
|
||||
app: null
|
||||
},
|
||||
|
@ -23,7 +23,7 @@ export default function webpackServerConfig() {
|
||||
config = Object.assign(config, {
|
||||
target: 'node',
|
||||
node: false,
|
||||
devtool: 'source-map',
|
||||
devtool: this.options.dev ? config.devtool : 'source-map',
|
||||
entry: resolve(this.options.buildDir, 'server.js'),
|
||||
output: Object.assign({}, config.output, {
|
||||
filename: 'server-bundle.js',
|
||||
|
@ -268,3 +268,16 @@ export function createRoutes(files, srcDir) {
|
||||
})
|
||||
return cleanChildrenRoutes(routes)
|
||||
}
|
||||
|
||||
export 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user