-
Notifications
You must be signed in to change notification settings - Fork 934
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
Minified Console Build #3805
Changes from 3 commits
a10ee8c
b66d623
be2671d
2f21579
65b9d42
3787f44
b33da3f
4808d25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
|
@@ -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 | ||
// 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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You didn't include I'm not sure why this works. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tree-shaking seems to work as I don't see |
||
external: rollupUtil.resolveBrowserExterns, | ||
treeshake: { | ||
moduleSideEffects: false | ||
} | ||
}; | ||
|
||
const es2017toEs5OutputOptions = { | ||
file: 'dist/standalone.js', | ||
name: EXPORTNAME, | ||
format: 'iife' | ||
|
@@ -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(); |
There was a problem hiding this comment.
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
andFirstPartyCredentialsSettings
. Once they are removed, the mangling works again.The issue seems to be that they are not included in the public externs.
There was a problem hiding this comment.
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.