mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
feat: automatically mock unresolved externals
This commit is contained in:
parent
5c8ac226f1
commit
b5b585c0c8
16
packages/nitro/src/rollup/automock.ts
Normal file
16
packages/nitro/src/rollup/automock.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import consola from 'consola'
|
||||||
|
|
||||||
|
export function autoMock () {
|
||||||
|
return {
|
||||||
|
name: 'auto-mock',
|
||||||
|
resolveId (src: string) {
|
||||||
|
if (src && !src.startsWith('.') && !src.includes('?') && !src.includes('.js')) {
|
||||||
|
consola.info('Automatically mocking', src)
|
||||||
|
return {
|
||||||
|
id: require.resolve('@nuxt/un/runtime/mock/proxy')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@ import { resolvePath, MODULE_DIR } from '../utils'
|
|||||||
import { dynamicRequire } from './dynamic-require'
|
import { dynamicRequire } from './dynamic-require'
|
||||||
import { externals } from './externals'
|
import { externals } from './externals'
|
||||||
import { timing } from './timing'
|
import { timing } from './timing'
|
||||||
|
import { autoMock } from './automock'
|
||||||
|
|
||||||
export type RollupConfig = InputOptions & { output: OutputOptions }
|
export type RollupConfig = InputOptions & { output: OutputOptions }
|
||||||
|
|
||||||
@ -179,6 +180,9 @@ export const getRollupConfig = (sigmaContext: SigmaContext) => {
|
|||||||
mainFields: ['main'] // Force resolve CJS (@vue/runtime-core ssrUtils)
|
mainFields: ['main'] // Force resolve CJS (@vue/runtime-core ssrUtils)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// Automatically mock unresolved externals
|
||||||
|
rollupConfig.plugins.push(autoMock())
|
||||||
|
|
||||||
// https://github.com/rollup/plugins/tree/master/packages/commonjs
|
// https://github.com/rollup/plugins/tree/master/packages/commonjs
|
||||||
rollupConfig.plugins.push(commonjs({
|
rollupConfig.plugins.push(commonjs({
|
||||||
extensions: extensions.filter(ext => ext !== '.json')
|
extensions: extensions.filter(ext => ext !== '.json')
|
||||||
|
Loading…
Reference in New Issue
Block a user