Skip to content

Commit c08c6f8

Browse files
LuudJanssenwti806
authored andcommitted
Remove dependencies from ES module (#623)
* Move material-design-lite to the dependencies * Split dependencies for ES modules and CommonJS modules
1 parent e68e301 commit c08c6f8

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

gulpfile.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,29 @@ const ESM_DIALOG_POLYFILL = 'if(typeof window!==\'undefined\')' +
5353
const 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.
6281
const 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.
120129
const 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.
289299
repeatTaskForAllLocales(
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.
301311
const 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.
306316
gulp.task('build-js', gulp.series(

package-lock.json

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@
5151
"gulp-css-inline-images": "^0.1.1",
5252
"gulp-sass": "^2.3.2",
5353
"gulp-util": "^3.0.7",
54-
"material-design-lite": "^1.2.0",
5554
"protractor": "^5.3.2",
5655
"streamqueue": "^1.1.1"
5756
},
5857
"dependencies": {
59-
"dialog-polyfill": "^0.4.7"
58+
"dialog-polyfill": "^0.4.7",
59+
"material-design-lite": "^1.2.0"
6060
},
6161
"peerDependencies": {
6262
"firebase": ">=6.6.0"

0 commit comments

Comments
 (0)