Skip to content

De-mangle Node and CJS build #2658

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 1 commit into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
56 changes: 35 additions & 21 deletions packages/firestore/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const transformers = [

const terserOptions = {
output: {
comments: false
comments: "all",
beautify: true
},
mangle: {
properties: {
Expand All @@ -60,19 +61,6 @@ const terserOptions = {
}
};

/**
* ES5 Builds
*/
const es5BuildPlugins = [
typescriptPlugin({
typescript,
transformers,
cacheRoot: './.cache/es5.min/'
}),
json(),
terser(terserOptions)
];

const es5Builds = [
/**
* Node.js Build
Expand All @@ -81,7 +69,11 @@ const es5Builds = [
input: 'index.node.ts',
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
plugins: [
...es5BuildPlugins,
typescriptPlugin({
typescript,
cacheRoot: './.cache/node.cjs/'
}),
json(),
// Needed as we also use the *.proto files
copy({
assets: ['./src/protos']
Expand All @@ -96,15 +88,37 @@ const es5Builds = [
)
},
/**
* Browser Builds
* Browser CJS Build
*
* The Browser CJS build is not mangled as Terser's property name mangling
Copy link
Member

Choose a reason for hiding this comment

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

Is CJS format the root of the issue? I thought only the Node build is affected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CJS build that we published contains a bunch of variables prefixed with _PRIVATE, which are not renamed by Terser. As such, the file is bigger than before.
firebase-firestore.js uses the ESM build, before converting to CJS, which means it is not affected.

* does not work well with CommonJS-style files.
*/
{
input: 'index.ts',
output: [
{ file: pkg.browser, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
output:{ file: pkg.browser, format: 'cjs', sourcemap: true },
plugins: [
typescriptPlugin({
typescript,
cacheRoot: './.cache/cjs/'
}),
json()
],
},
/**
* Browser ESM Build
*/
{
input: 'index.ts',
output: { file: pkg.module, format: 'es', sourcemap: true },
plugins: [
typescriptPlugin({
typescript,
transformers,
cacheRoot: './.cache/esm/'
}),
json(),
terser(terserOptions)
],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];
Expand All @@ -120,7 +134,7 @@ const es2017BuildPlugins = [
target: 'es2017'
}
},
cacheRoot: './.cache/es2017.min/',
cacheRoot: './.cache/esm2017/',
transformers
}),
json({ preferConst: true }),
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/util/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function makeConstructorPrivate<T extends Function>(

// Copy any static methods/members
Object.assign(PublicConstructor, cls);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
return PublicConstructor as any;
}