mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
fix(app): separate plugin entrypoints (#366)
This commit is contained in:
parent
d6d12d1b87
commit
f980ef235f
@ -1,20 +0,0 @@
|
||||
import preload from '#app/plugins/preload.server'
|
||||
|
||||
<%= utils.importSources(app.plugins.map(p => p.src)) %>
|
||||
|
||||
const commonPlugins = [
|
||||
<%= app.plugins.filter(p => !p.mode || p.mode === 'all').map(p => utils.importName(p.src)).join(',\n ') %>
|
||||
]
|
||||
|
||||
export const clientPlugins = [
|
||||
...commonPlugins,
|
||||
<%= app.plugins.filter(p => p.mode === 'client').map(p => utils.importName(p.src)).join(',\n ') %>
|
||||
]
|
||||
|
||||
export const serverPlugins = [
|
||||
...commonPlugins,
|
||||
preload,
|
||||
<%= app.plugins.filter(p => p.mode === 'server').map(p => utils.importName(p.src)).join(',\n ') %>
|
||||
]
|
||||
|
||||
export default process.client ? clientPlugins : serverPlugins
|
5
packages/app/src/_templates/plugins/client.mjs
Normal file
5
packages/app/src/_templates/plugins/client.mjs
Normal file
@ -0,0 +1,5 @@
|
||||
<%= utils.importSources(app.plugins.filter(p => !p.mode || p.mode !== 'server').map(p => p.src)) %>
|
||||
|
||||
export default [
|
||||
<%= app.plugins.filter(p => !p.mode || p.mode !== 'server').map(p => utils.importName(p.src)).join(',\n ') %>
|
||||
]
|
8
packages/app/src/_templates/plugins/server.mjs
Normal file
8
packages/app/src/_templates/plugins/server.mjs
Normal file
@ -0,0 +1,8 @@
|
||||
import preload from '#app/plugins/preload.server'
|
||||
|
||||
<%= utils.importSources(app.plugins.filter(p => !p.mode || p.mode !== 'client').map(p => p.src)) %>
|
||||
|
||||
export default [
|
||||
preload,
|
||||
<%= app.plugins.filter(p => !p.mode || p.mode !== 'client').map(p => utils.importName(p.src)).join(',\n ') %>
|
||||
]
|
@ -15,6 +15,11 @@ export async function buildClient (ctx: ViteBuildContext) {
|
||||
'module.hot': false,
|
||||
global: 'globalThis'
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'#build/plugins': resolve(ctx.nuxt.options.buildDir, 'plugins/client')
|
||||
}
|
||||
},
|
||||
build: {
|
||||
outDir: 'dist/client',
|
||||
assetsDir: '.'
|
||||
|
@ -18,6 +18,11 @@ export async function buildServer (ctx: ViteBuildContext) {
|
||||
'typeof location': '"undefined"',
|
||||
'typeof XMLHttpRequest': '"undefined"'
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'#build/plugins': resolve(ctx.nuxt.options.buildDir, 'plugins/server')
|
||||
}
|
||||
},
|
||||
ssr: {
|
||||
external: [
|
||||
'axios'
|
||||
|
@ -36,6 +36,9 @@ export async function bundle (nuxt: Nuxt) {
|
||||
alias: {
|
||||
...nuxt.options.alias,
|
||||
'#app': nuxt.options.appDir,
|
||||
// We need this resolution to be present before the following entry, but it
|
||||
// will be filled in client/server configs
|
||||
'#build/plugins': undefined,
|
||||
'#build': nuxt.options.buildDir,
|
||||
'/build': nuxt.options.buildDir,
|
||||
'/app': nuxt.options.appDir,
|
||||
|
@ -110,6 +110,7 @@ function baseAlias (ctx: WebpackConfigContext) {
|
||||
|
||||
ctx.alias = {
|
||||
'#app': options.appDir,
|
||||
'#build/plugins': resolve(options.buildDir, 'plugins', ctx.isClient ? 'client' : 'server'),
|
||||
'#build': options.buildDir,
|
||||
...options.alias,
|
||||
...ctx.alias
|
||||
|
Loading…
Reference in New Issue
Block a user