@@ -11,7 +11,11 @@ import { removeCollectionImports } from '../../transformers/remove-collection-im
11
11
import { STENCIL_INTERNAL_CLIENT_ID , USER_INDEX_ENTRY_ID , STENCIL_APP_GLOBALS_ID } from '../../bundle/entry-alias-ids' ;
12
12
import { updateStencilCoreImports } from '../../transformers/update-stencil-core-import' ;
13
13
14
- export const outputCustomElementsBundle = async ( config : d . Config , compilerCtx : d . CompilerCtx , buildCtx : d . BuildCtx ) => {
14
+ export const outputCustomElementsBundle = async (
15
+ config : d . Config ,
16
+ compilerCtx : d . CompilerCtx ,
17
+ buildCtx : d . BuildCtx ,
18
+ ) => {
15
19
if ( ! config . buildDist ) {
16
20
return ;
17
21
}
@@ -28,7 +32,12 @@ export const outputCustomElementsBundle = async (config: d.Config, compilerCtx:
28
32
timespan . finish ( `generate custom elements bundle finished` ) ;
29
33
} ;
30
34
31
- const bundleCustomElements = async ( config : d . Config , compilerCtx : d . CompilerCtx , buildCtx : d . BuildCtx , outputTarget : d . OutputTargetDistCustomElementsBundle ) => {
35
+ const bundleCustomElements = async (
36
+ config : d . Config ,
37
+ compilerCtx : d . CompilerCtx ,
38
+ buildCtx : d . BuildCtx ,
39
+ outputTarget : d . OutputTargetDistCustomElementsBundle ,
40
+ ) => {
32
41
try {
33
42
const bundleOpts : BundleOptions = {
34
43
id : 'customElementsBundle' ,
@@ -41,7 +50,7 @@ const bundleCustomElements = async (config: d.Config, compilerCtx: d.CompilerCtx
41
50
index : '\0core' ,
42
51
} ,
43
52
loader : {
44
- '\0core' : generateEntryPoint ( buildCtx ) ,
53
+ '\0core' : generateEntryPoint ( outputTarget , buildCtx ) ,
45
54
} ,
46
55
inlineDynamicImports : outputTarget . inlineDynamicImports ,
47
56
preserveEntrySignatures : 'allow-extension' ,
@@ -69,7 +78,9 @@ const bundleCustomElements = async (config: d.Config, compilerCtx: d.CompilerCtx
69
78
if ( ! hasError ( optimizeResults . diagnostics ) && typeof optimizeResults . output === 'string' ) {
70
79
code = optimizeResults . output ;
71
80
}
72
- await compilerCtx . fs . writeFile ( join ( outputTarget . dir , bundle . fileName ) , code , { outputTargetType : outputTarget . type } ) ;
81
+ await compilerCtx . fs . writeFile ( join ( outputTarget . dir , bundle . fileName ) , code , {
82
+ outputTargetType : outputTarget . type ,
83
+ } ) ;
73
84
}
74
85
} ) ;
75
86
await Promise . all ( files ) ;
@@ -79,7 +90,7 @@ const bundleCustomElements = async (config: d.Config, compilerCtx: d.CompilerCtx
79
90
}
80
91
} ;
81
92
82
- const generateEntryPoint = ( buildCtx : d . BuildCtx ) => {
93
+ const generateEntryPoint = ( outputTarget : d . OutputTargetDistCustomElementsBundle , buildCtx : d . BuildCtx ) => {
83
94
const imp : string [ ] = [ ] ;
84
95
const exp : string [ ] = [ ] ;
85
96
const exportNames : string [ ] = [ ] ;
@@ -88,10 +99,12 @@ const generateEntryPoint = (buildCtx: d.BuildCtx) => {
88
99
`import { proxyCustomElement } from '${ STENCIL_INTERNAL_CLIENT_ID } ';` ,
89
100
`export { setAssetPath } from '${ STENCIL_INTERNAL_CLIENT_ID } ';` ,
90
101
`export * from '${ USER_INDEX_ENTRY_ID } ';` ,
91
- `import { globalScripts } from '${ STENCIL_APP_GLOBALS_ID } ';` ,
92
- `globalScripts();` ,
93
102
) ;
94
103
104
+ if ( outputTarget . includeGlobalScripts !== false ) {
105
+ imp . push ( `import { globalScripts } from '${ STENCIL_APP_GLOBALS_ID } ';` , `globalScripts();` ) ;
106
+ }
107
+
95
108
buildCtx . components . forEach ( cmp => {
96
109
const exportName = dashToPascalCase ( cmp . tagName ) ;
97
110
const importName = cmp . componentClassName ;
@@ -133,5 +146,9 @@ const getCustomElementBundleCustomTransformer = (config: d.Config, compilerCtx:
133
146
style : 'static' ,
134
147
styleImportData : 'queryparams' ,
135
148
} ;
136
- return [ updateStencilCoreImports ( transformOpts . coreImportPath ) , nativeComponentTransform ( compilerCtx , transformOpts ) , removeCollectionImports ( compilerCtx ) ] ;
149
+ return [
150
+ updateStencilCoreImports ( transformOpts . coreImportPath ) ,
151
+ nativeComponentTransform ( compilerCtx , transformOpts ) ,
152
+ removeCollectionImports ( compilerCtx ) ,
153
+ ] ;
137
154
} ;
0 commit comments