@@ -53,10 +53,29 @@ const ESM_DIALOG_POLYFILL = 'if(typeof window!==\'undefined\')' +
5353const DEFAULT_IMPORT_FIX = 'if(typeof firebase.default!==\'undefined\')' +
5454 '{firebase=firebase.default;}' ;
5555
56+ // The Material Design Lite components needed by FirebaseUI.
57+ const MDL_COMPONENTS = [
58+ 'mdlComponentHandler' ,
59+ 'button/button' ,
60+ 'progress/progress' ,
61+ 'spinner/spinner' ,
62+ 'textfield/textfield'
63+ ]
64+
65+ // The external dependencies needed by FirebaseUI as ES module imports.
66+ const ESM_DEPS = [
67+ 'import * as firebase from \'firebase/app\'' ,
68+ 'import \'firebase/auth\'' ,
69+ 'import dialogPolyfill from \'dialog-polyfill\'' ,
70+ ] . concat ( MDL_COMPONENTS . map ( component => `import \'material-design-lite/src/${ component } \'` ) )
71+
72+ // The external dependencies needed by FirebaseUI as CommonJS modules.
73+ const CJS_DEPS = [
74+ 'node_modules/dialog-polyfill/dialog-polyfill.js'
75+ ] . concat ( MDL_COMPONENTS . map ( component => `node_modules/material-design-lite/src/${ component } .js` ) ) ;
76+
5677// Import esm modules.
57- const ESM_IMPORT = 'import * as firebase from \'firebase/app\';' +
58- 'import \'firebase/auth\';' +
59- 'import dialogPolyfill from \'dialog-polyfill\';' ;
78+ const ESM_IMPORT = ESM_DEPS . join ( ';' ) + ';' ;
6079
6180// Export firebaseui.auth module.
6281const ESM_EXPORT = 'const auth = firebaseui.auth;' +
@@ -106,16 +125,6 @@ const COMPILER_DEFAULT_ARGS = {
106125 language_out : 'ES5'
107126} ;
108127
109- // The external dependencies needed by FirebaseUI.
110- const JS_DEPS = [
111- 'node_modules/material-design-lite/src/mdlComponentHandler.js' ,
112- 'node_modules/material-design-lite/src/button/button.js' ,
113- 'node_modules/material-design-lite/src/progress/progress.js' ,
114- 'node_modules/material-design-lite/src/spinner/spinner.js' ,
115- 'node_modules/material-design-lite/src/textfield/textfield.js' ,
116- 'node_modules/dialog-polyfill/dialog-polyfill.js'
117- ] ;
118-
119128// The typescript definitions file path.
120129const TYPES_FILE = './types/index.d.ts' ;
121130
@@ -241,12 +250,13 @@ function buildFirebaseUiJs(locale) {
241250 * @param {string } locale The desired FirebaseUI locale.
242251 * @param {string } outBaseName The prefix of the output file name.
243252 * @param {string } outputWrapper A wrapper with which to wrap the output JS.
253+ * @param {string[] } dependencies The dependencies to concatenate.
244254 * @return {* } A stream that ends when compilation finishes.
245255 */
246- function concatWithDeps ( locale , outBaseName , outputWrapper ) {
256+ function concatWithDeps ( locale , outBaseName , outputWrapper , dependencies = [ ] ) {
247257 const localeForFileName = getLocaleForFileName ( locale ) ;
248258 // Get a list of the FirebaseUI JS and its dependencies.
249- const srcs = JS_DEPS . concat ( [ getTmpJsPath ( locale ) ] ) ;
259+ const srcs = dependencies . concat ( [ getTmpJsPath ( locale ) ] ) ;
250260 const outputPath = `${ DEST_DIR } /${ outBaseName } __${ localeForFileName } .js` ;
251261 return compile ( srcs , outputPath , {
252262 compilation_level : 'WHITESPACE_ONLY' ,
@@ -288,7 +298,7 @@ repeatTaskForAllLocales(
288298// the NPM module for all languages.
289299repeatTaskForAllLocales (
290300 'build-npm-$' , [ 'build-firebaseui-js-$' ] ,
291- ( locale ) => concatWithDeps ( locale , 'npm' , NPM_MODULE_WRAPPER ) ) ;
301+ ( locale ) => concatWithDeps ( locale , 'npm' , NPM_MODULE_WRAPPER , CJS_DEPS ) ) ;
292302
293303// Bundles the FirebaseUI JS with its dependencies as a ESM module. This builds
294304// the NPM module for all languages.
@@ -300,7 +310,7 @@ repeatTaskForAllLocales(
300310// Generates the gulp tasks build-js-de, build-js-fr, etc.
301311const buildJsTasks = repeatTaskForAllLocales (
302312 'build-js-$' , [ 'build-firebaseui-js-$' ] ,
303- ( locale ) => concatWithDeps ( locale , 'firebaseui' , OUTPUT_WRAPPER ) ) ;
313+ ( locale ) => concatWithDeps ( locale , 'firebaseui' , OUTPUT_WRAPPER , CJS_DEPS ) ) ;
304314
305315// Builds the final JS file for the default language.
306316gulp . task ( 'build-js' , gulp . series (
0 commit comments