mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
feat: improve mocks
This commit is contained in:
parent
a9a66879de
commit
6ff7c7e02e
@ -18,7 +18,7 @@ import dynamicRequire from './dynamic-require'
|
||||
export type RollupConfig = InputOptions & { output: OutputOptions }
|
||||
|
||||
export const getRollupConfig = (config: SLSOptions) => {
|
||||
const mocks = [
|
||||
const genericMocks = [
|
||||
// @nuxt/devalue
|
||||
'consola',
|
||||
// vue2
|
||||
@ -46,8 +46,21 @@ export const getRollupConfig = (config: SLSOptions) => {
|
||||
|
||||
const external = []
|
||||
|
||||
const aliases: {[key: string]: string} = {}
|
||||
|
||||
if (config.node === false) {
|
||||
mocks.push(...Module.builtinModules)
|
||||
// Generic mocks
|
||||
Object.assign(aliases, [...genericMocks, ...Module.builtinModules].reduce((p, c) => ({ ...p, [c]: '~mock' }), {}))
|
||||
|
||||
// Custom
|
||||
aliases.depd = '~runtime/mocks/depd'
|
||||
aliases.http = '~runtime/mocks/http'
|
||||
|
||||
// Builtin (browserify)
|
||||
aliases.buffer = require.resolve('buffer/index.js')
|
||||
aliases.util = require.resolve('util/util.js')
|
||||
aliases.events = require.resolve('events/events.js')
|
||||
aliases.inherits = require.resolve('inherits/inherits_browser.js')
|
||||
} else {
|
||||
external.push(...Module.builtinModules)
|
||||
}
|
||||
@ -118,9 +131,9 @@ export const getRollupConfig = (config: SLSOptions) => {
|
||||
'~runtime': config.runtimeDir,
|
||||
'~renderer': require.resolve(resolve(config.runtimeDir, 'ssr', renderer)),
|
||||
'~build': config.buildDir,
|
||||
'~mock': require.resolve(resolve(config.runtimeDir, 'utils/mock')),
|
||||
...mocks.reduce((p, c) => ({ ...p, [c]: '~mock' }), {}),
|
||||
...providedDeps.reduce((p, c) => ({ ...p, [c]: require.resolve(c) }), {})
|
||||
'~mock': require.resolve(resolve(config.runtimeDir, 'mocks/generic')),
|
||||
...providedDeps.reduce((p, c) => ({ ...p, [c]: require.resolve(c) }), {}),
|
||||
...aliases
|
||||
}
|
||||
}))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user