@@ -37,17 +37,32 @@ const OPTIMIZATION_LEVEL = util.env.compilation_level ||
37
37
38
38
// For minified builds, wrap the output so we avoid leaking global variables.
39
39
const OUTPUT_WRAPPER = OPTIMIZATION_LEVEL === 'WHITESPACE_ONLY' ?
40
- '%output%' : '(function() { %output% })();' ;
40
+ '%output%' : '(function() { %output% }).apply(' +
41
+ 'typeof global !== \'undefined\' ? global : typeof self !== \'undefined\' ' +
42
+ '? self : window );' ;
41
43
42
- // Provides missing dialogPolyfill on window in npm environments.
44
+ // Provides missing dialogPolyfill on window in cjs environments.
43
45
const DIALOG_POLYFILL = 'if(typeof window!==\'undefined\')' +
44
46
'{window.dialogPolyfill=require(\'dialog-polyfill\');}' ;
45
47
48
+ // Provides missing dialogPolyfill on window for esm.
49
+ const ESM_DIALOG_POLYFILL = 'if(typeof window!==\'undefined\')' +
50
+ '{window.dialogPolyfill=dialogPolyfill;}' ;
51
+
46
52
// Using default import if available.
47
53
const DEFAULT_IMPORT_FIX = 'if(typeof firebase.default!==\'undefined\')' +
48
54
'{firebase=firebase.default;}' ;
49
55
50
- // Adds the module requirement and exports firebaseui.
56
+ // Import esm modules.
57
+ const ESM_IMPORT = 'import * as firebase from \'firebase/app\';' +
58
+ 'import \'firebase/auth\';' +
59
+ 'import dialogPolyfill from \'dialog-polyfill\';' ;
60
+
61
+ // Export firebaseui.auth module.
62
+ const ESM_EXPORT = 'const auth = firebaseui.auth;' +
63
+ 'export { auth } ;' ;
64
+
65
+ // Adds the cjs module requirement and exports firebaseui.
51
66
const NPM_MODULE_WRAPPER = OPTIMIZATION_LEVEL === 'WHITESPACE_ONLY' ?
52
67
'var firebase=require(\'firebase/app\');require(\'firebase/auth\');' +
53
68
DEFAULT_IMPORT_FIX + '%output%' + DIALOG_POLYFILL +
@@ -56,6 +71,16 @@ const NPM_MODULE_WRAPPER = OPTIMIZATION_LEVEL === 'WHITESPACE_ONLY' ?
56
71
'require(\'firebase/auth\');' + DEFAULT_IMPORT_FIX + '%output% ' +
57
72
DIALOG_POLYFILL + '})();' + 'module.exports=firebaseui;' ;
58
73
74
+ // Adds the module requirement and exports firebaseui.
75
+ const ESM_MODULE_WRAPPER = OPTIMIZATION_LEVEL === 'WHITESPACE_ONLY' ?
76
+ ESM_IMPORT + '%output%' +
77
+ ESM_DIALOG_POLYFILL + ESM_EXPORT :
78
+ ESM_IMPORT +
79
+ '(function() {' + '%output%' + '}).apply(' +
80
+ 'typeof global !== \'undefined\' ? global : typeof self !== \'undefined\' ' +
81
+ '? self : window );' +
82
+ ESM_DIALOG_POLYFILL + ESM_EXPORT ;
83
+
59
84
// The path to Closure Compiler.
60
85
const COMPILER_PATH = 'node_modules/google-closure-compiler-java/compiler.jar' ;
61
86
@@ -265,6 +290,12 @@ repeatTaskForAllLocales(
265
290
'build-npm-$' , [ 'build-firebaseui-js-$' ] ,
266
291
( locale ) => concatWithDeps ( locale , 'npm' , NPM_MODULE_WRAPPER ) ) ;
267
292
293
+ // Bundles the FirebaseUI JS with its dependencies as a ESM module. This builds
294
+ // the NPM module for all languages.
295
+ repeatTaskForAllLocales (
296
+ 'build-esm-$' , [ 'build-firebaseui-js-$' ] ,
297
+ ( locale ) => concatWithDeps ( locale , 'esm' , ESM_MODULE_WRAPPER ) ) ;
298
+
268
299
// Bundles the FirebaseUI JS with its dependencies for all locales.
269
300
// Generates the gulp tasks build-js-de, build-js-fr, etc.
270
301
const buildJsTasks = repeatTaskForAllLocales (
@@ -289,6 +320,12 @@ gulp.task('build-npm', gulp.series(
289
320
( ) => makeDefaultFile ( 'npm' )
290
321
) ) ;
291
322
323
+ // Builds the ESM module for the default language.
324
+ gulp . task ( 'build-esm' , gulp . series (
325
+ 'build-esm-' + DEFAULT_LOCALE ,
326
+ ( ) => makeDefaultFile ( 'esm' )
327
+ ) ) ;
328
+
292
329
/**
293
330
* Builds the CSS for FirebaseUI.
294
331
* @param {boolean } isRtl Whether to build in right-to-left mode.
@@ -336,13 +373,13 @@ gulp.task('clean', () => fse.remove(TMP_DIR));
336
373
// Executes the basic tasks for the default language.
337
374
gulp . task ( 'default' , gulp . series (
338
375
'build-externs' , 'build-ts' , 'build-js' ,
339
- 'build-npm' , 'build-css' , 'build-css-rtl' ,
376
+ 'build-npm' , 'build-esm' , 'build- css', 'build-css-rtl' ,
340
377
'clean'
341
378
) ) ;
342
379
343
380
// Builds everything (JS for all languages, both LTR and RTL CSS).
344
381
gulp . task ( 'build-all' , gulp . series (
345
382
'build-externs' , 'build-ts' , 'build-all-js' ,
346
- 'build-npm' , 'build-css' , 'build-css-rtl' ,
383
+ 'build-npm' , 'build-esm' , 'build- css', 'build-css-rtl' ,
347
384
'clean'
348
385
) ) ;
0 commit comments