This commit is contained in:
2022-07-18 02:50:52 +00:00
parent befd344ab0
commit 06181b34d6
8569 changed files with 818704 additions and 352705 deletions
+44 -7
View File
@@ -1,9 +1,46 @@
<%= options.getComponents().filter(c => !c.async).map(c => {
const exp = c.pascalName === c.export ? c.pascalName : `${c.export} as ${c.pascalName}`
return `export { ${exp} } from '../${relativeToBuild(c.filePath)}'`
<%= options.getComponents().map(c => {
const magicComments = [
`webpackChunkName: "${c.chunkName}"`,
c.prefetch === true || typeof c.prefetch === 'number' ? `webpackPrefetch: ${c.prefetch}` : false,
c.preload === true || typeof c.preload === 'number' ? `webpackPreload: ${c.preload}` : false,
].filter(Boolean).join(', ')
if (c.isAsync === true || (!isDev /* prod fallback */ && c.isAsync === null)) {
const exp = c.export === 'default' ? `c.default || c` : `c['${c.export}']`
const asyncImport = `() => import('../${relativeToBuild(c.filePath)}' /* ${magicComments} */).then(c => wrapFunctional(${exp}))`
return `export const ${c.pascalName} = ${asyncImport}`
} else {
const exp = c.export === 'default' ? `default as ${c.pascalName}` : c.pascalName
return `export { ${exp} } from '../${relativeToBuild(c.filePath)}'`
}
}).join('\n') %>
<%= options.getComponents().filter(c => c.async).map(c => {
const exp = c.export === 'default' ? `c.default || c` : `c['${c.export}']`
return `export const ${c.pascalName} = import('../${relativeToBuild(c.filePath)}' /* webpackChunkName: "${c.chunkName}'}" */).then(c => ${exp})`
}).join('\n') %>
// nuxt/nuxt.js#8607
function wrapFunctional(options) {
if (!options || !options.functional) {
return options
}
const propKeys = Array.isArray(options.props) ? options.props : Object.keys(options.props || {})
return {
render(h) {
const attrs = {}
const props = {}
for (const key in this.$attrs) {
if (propKeys.includes(key)) {
props[key] = this.$attrs[key]
} else {
attrs[key] = this.$attrs[key]
}
}
return h(options, {
on: this.$listeners,
attrs,
props,
scopedSlots: this.$scopedSlots,
}, this.$slots.default)
}
}
}
+4 -10
View File
@@ -1,13 +1,7 @@
import Vue from 'vue'
<% const globalComponents = options.getComponents().filter(c => c.global && c.async) %>
import * as components from './index'
const globalComponents = {
<%= globalComponents.map(c => {
const exp = c.export === 'default' ? `c.default || c` : `c['${c.export}']`
return ` ${c.pascalName.replace(/^Lazy/, '')}: () => import('../${relativeToBuild(c.filePath)}' /* webpackChunkName: "${c.chunkName}" */).then(c => ${exp})`
}).join(',\n') %>
}
for (const name in globalComponents) {
Vue.component(name, globalComponents[name])
for (const name in components) {
Vue.component(name, components[name])
Vue.component('Lazy' + name, components[name])
}
+17
View File
@@ -0,0 +1,17 @@
# Discovered Components
This is an auto-generated list of components discovered by [nuxt/components](https://github.com/nuxt/components).
You can directly use them in pages and other components without the need to import them.
**Tip:** If a component is conditionally rendered with `v-if` and is big, it is better to use `Lazy` or `lazy-` prefix to lazy load.
<%
const components = options.getComponents()
const list = components.map(c => {
const pascalName = c.pascalName.replace(/^Lazy/, '')
const kebabName = c.kebabName.replace(/^lazy-/, '')
const tags = c.isAsync ? ' [async]' : ''
return `- \`<${pascalName}>\` | \`<${kebabName}>\` (${c.shortPath})${tags}`
})
%><%= list.join('\n') %>