refactor: plugin templates (#1678)

Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
Anthony Fu 2021-11-04 16:16:54 +08:00 committed by GitHub
parent 85f39858e5
commit 929a634013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,11 +33,11 @@ export const cssTemplate = {
export const clientPluginTemplate = {
filename: 'plugins/client.mjs',
getContents (ctx: TemplateContext) {
const { app } = ctx
const clientPlugins = ctx.app.plugins.filter(p => !p.mode || p.mode !== 'server')
return [
importSources(app.plugins.filter(p => !p.mode || p.mode !== 'server').map(p => p.src)),
importSources(clientPlugins.map(p => p.src)),
'export default [',
app.plugins.filter(p => !p.mode || p.mode !== 'server').map(p => importName(p.src)).join(',\n '),
clientPlugins.map(p => importName(p.src)).join(',\n '),
']'
].join('\n')
}
@ -46,13 +46,13 @@ export const clientPluginTemplate = {
export const serverPluginTemplate = {
filename: 'plugins/server.mjs',
getContents (ctx: TemplateContext) {
const { app } = ctx
const serverPlugins = ctx.app.plugins.filter(p => !p.mode || p.mode !== 'client')
return [
"import preload from '#app/plugins/preload.server'",
importSources(app.plugins.filter(p => !p.mode || p.mode !== 'client').map(p => p.src)),
importSources(serverPlugins.map(p => p.src)),
'export default [',
' preload,',
app.plugins.filter(p => !p.mode || p.mode !== 'client').map(p => importName(p.src)).join(',\n '),
serverPlugins.map(p => importName(p.src)).join(',\n '),
']'
].join('\n')
}