Skip to content

Minified Console Build #3805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/firestore/index.console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
* limitations under the License.
*/

// TODO(mrschmidt): Once imported into Google3, fix
// third_party/javascript/firebase/src/packages/firestore/tools/console.build.js

export { Firestore, FirestoreDatabase } from './src/api/database';
export {
CollectionReference,
Expand Down
62 changes: 37 additions & 25 deletions packages/firestore/tools/console.build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2019 Google Inc.
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,34 +19,44 @@
* Firebase console uses firestore in its special way.
* This file creates a build target for it.
*/
const tmp = require('tmp');
const rollup = require('rollup');
const typescriptPlugin = require('rollup-plugin-typescript2');
const typescript = require('typescript');
const resolve = require('rollup-plugin-node-resolve');
const { uglify } = require('rollup-plugin-uglify');
const fs = require('fs');
const util = require('util');
const fs_writeFile = util.promisify(fs.writeFile);

const plugins = [
resolve(),
typescriptPlugin({
typescript
}),
uglify({
output: {
ascii_only: true // escape unicode chars
}
})
];
const rollupUtil = require('../rollup.shared');

const EXPORTNAME = '__firestore_exports__';

const inputOptions = {
const tmpFile = tmp.fileSync().name;

const es2017InputOptions = {
input: 'index.console.ts',
plugins
// If I set mangled to true the build breaks, but all other build pipelines
Copy link
Member

@Feiyang1 Feiyang1 Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem comed from the 2 interface exports - FirestoreDatabase and FirstPartyCredentialsSettings. Once they are removed, the mangling works again.

The issue seems to be that they are not included in the public externs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the interfaces provide any value here since console uses the js output, so they can probably be removed.

// use the same settings
plugins: rollupUtil.es2017Plugins('browser', /* mangled= */ false),
external: rollupUtil.resolveBrowserExterns,
treeshake: {
moduleSideEffects: false
}
};

const es2017OutputOptions = {
file: tmpFile,
format: 'es'
};
const outputOptions = {

const es2017toEs5InputOptions = {
input: tmpFile,
plugins: rollupUtil.es2017ToEs5Plugins(/* mangled= */ true),
Copy link
Member

@Feiyang1 Feiyang1 Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't include tmpFile in the include array of the typescript plugin - https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/rollup.shared.js#L181, but including it didn't work either ( it seems that include doesn't like absolute paths). So I suggest creating a tmp file with .js extension in firestore/dist, which worked for me.

I'm not sure why this works. compilerOptions is supposed to be nested under tsconfigOverride instead of being at top level according to the doc and that's what we do for all other configs.

Copy link
Member

@Feiyang1 Feiyang1 Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tree-shaking seems to work as I don't see IndexedDbOfflineComponentProvider in the es2017 output which is not mangled.

external: rollupUtil.resolveBrowserExterns,
treeshake: {
moduleSideEffects: false
}
};

const es2017toEs5OutputOptions = {
file: 'dist/standalone.js',
name: EXPORTNAME,
format: 'iife'
Expand All @@ -59,17 +69,19 @@ exports = eval(`;
const POSTFIX = ` + '${EXPORTNAME};');`;

async function build() {
// create a bundle
const bundle = await rollup.rollup(inputOptions);
// create an ES2017 bundle
const es2017Bundle = await rollup.rollup(es2017InputOptions);
await es2017Bundle.write(es2017OutputOptions);
console.log(tmpFile);

// generate code
const es5Bundle = await rollup.rollup(es2017toEs5InputOptions);
const {
output: [{ code }]
} = await bundle.generate(outputOptions);
} = await es5Bundle.generate(es2017toEs5OutputOptions);

// The output file is HUGE and uses classes still
const output = `${PREFIX}${JSON.stringify(String(code))}${POSTFIX}`;

await fs_writeFile(outputOptions.file, output, 'utf-8');
await fs_writeFile(es2017toEs5OutputOptions.file, output, 'utf-8');
}

build();