1
1
import {
2
+ ConfigEnv ,
2
3
ExtensionRunnerConfig ,
3
4
InlineConfig ,
4
5
InternalConfig ,
5
6
UserConfig ,
6
7
UserManifest ,
8
+ UserManifestFn ,
7
9
} from '../types' ;
8
10
import path , { resolve } from 'node:path' ;
9
11
import * as vite from 'vite' ;
@@ -32,15 +34,6 @@ export async function getInternalConfig(
32
34
const outDir = path . resolve ( outBaseDir , `${ browser } -mv${ manifestVersion } ` ) ;
33
35
const logger = config . logger ?? consola ;
34
36
35
- const manifest : UserManifest = await ( typeof config . manifest === 'function'
36
- ? config . manifest ( {
37
- browser,
38
- command,
39
- manifestVersion,
40
- mode,
41
- } )
42
- : config . manifest ?? { } ) ;
43
-
44
37
const baseConfig : InternalConfigNoUserDirs = {
45
38
root,
46
39
outDir,
@@ -52,7 +45,6 @@ export async function getInternalConfig(
52
45
command,
53
46
logger,
54
47
vite : config . vite ?? { } ,
55
- manifest,
56
48
imports : config . imports ?? { } ,
57
49
runnerConfig : await loadConfig < ExtensionRunnerConfig > ( {
58
50
name : 'web-ext' ,
@@ -92,6 +84,12 @@ export async function getInternalConfig(
92
84
const wxtDir = resolve ( srcDir , '.wxt' ) ;
93
85
const typesDir = resolve ( wxtDir , 'types' ) ;
94
86
87
+ // Merge manifest sources
88
+ const env : ConfigEnv = { mode, browser, manifestVersion, command } ;
89
+ const userManifest = await resolveManifestConfig ( env , userConfig . manifest ) ;
90
+ const inlineManifest = await resolveManifestConfig ( env , config . manifest ) ;
91
+ const manifest = vite . mergeConfig ( userManifest , inlineManifest ) ;
92
+
95
93
const finalConfig : InternalConfig = {
96
94
...merged ,
97
95
srcDir,
@@ -100,6 +98,7 @@ export async function getInternalConfig(
100
98
wxtDir : wxtDir ,
101
99
typesDir,
102
100
fsCache : createFsCache ( wxtDir ) ,
101
+ manifest,
103
102
} ;
104
103
105
104
// Customize the default vite config
@@ -137,5 +136,20 @@ export async function getInternalConfig(
137
136
*/
138
137
type InternalConfigNoUserDirs = Omit <
139
138
InternalConfig ,
140
- 'srcDir' | 'publicDir' | 'entrypointsDir' | 'wxtDir' | 'typesDir' | 'fsCache'
139
+ | 'srcDir'
140
+ | 'publicDir'
141
+ | 'entrypointsDir'
142
+ | 'wxtDir'
143
+ | 'typesDir'
144
+ | 'fsCache'
145
+ | 'manifest'
141
146
> ;
147
+
148
+ async function resolveManifestConfig (
149
+ env : ConfigEnv ,
150
+ manifest : UserManifest | Promise < UserManifest > | UserManifestFn | undefined ,
151
+ ) : Promise < UserManifest > {
152
+ return await ( typeof manifest === 'function'
153
+ ? manifest ( env )
154
+ : manifest ?? { } ) ;
155
+ }
0 commit comments