diff --git a/packages/firestore/package.json b/packages/firestore/package.json index fa305fdf4c5..c6f1640f1db 100644 --- a/packages/firestore/package.json +++ b/packages/firestore/package.json @@ -7,7 +7,8 @@ "description": "The Cloud Firestore component of the Firebase JS SDK.", "author": "Firebase (https://firebase.google.com/)", "scripts": { - "build": "rollup -c rollup.config.es2017.js && rollup -c rollup.config.es5.js && yarn build:lite && yarn build:exp", + "bundle": "rollup -c", + "build": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.browser.memory.js' 'bundle rollup.config.node.js' 'bundle rollup.config.node.memory.js' 'bundle rollup.config.rn.js' 'bundle rollup.config.rn.memory.js' build:lite build:exp", "build:scripts": "tsc -moduleResolution node --module commonjs scripts/*.ts && ls scripts/*.js | xargs -I % sh -c 'terser % -o %'", "build:release": "rollup -c rollup.config.es2017.js && rollup -c rollup.config.es5.js", "build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build", diff --git a/packages/firestore/rollup.config.browser.js b/packages/firestore/rollup.config.browser.js new file mode 100644 index 00000000000..e67528fb11b --- /dev/null +++ b/packages/firestore/rollup.config.browser.js @@ -0,0 +1,45 @@ +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import pkg from './package.json'; + +const util = require('./rollup.shared'); + +export default [ + { + input: 'index.ts', + output: { + file: pkg.esm2017, + format: 'es', + sourcemap: true + }, + plugins: util.es2017Plugins('browser', /* mangled= */ true), + external: util.resolveBrowserExterns + }, + { + input: pkg.esm2017, + output: { file: pkg.module, format: 'es', sourcemap: true }, + plugins: util.es2017ToEs5Plugins(/* mangled= */ true), + external: util.resolveBrowserExterns + }, + { + input: pkg.esm2017, + output: { file: pkg.browser, format: 'cjs', sourcemap: true }, + plugins: util.es2017ToEs5Plugins(/* mangled= */ true), + external: util.resolveBrowserExterns + } +]; diff --git a/packages/firestore/rollup.config.browser.memory.js b/packages/firestore/rollup.config.browser.memory.js new file mode 100644 index 00000000000..5cf0c636d62 --- /dev/null +++ b/packages/firestore/rollup.config.browser.memory.js @@ -0,0 +1,54 @@ +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as path from 'path'; +import memoryPkg from './memory/package.json'; + +const util = require('./rollup.shared'); + +export default [ + { + input: 'index.memory.ts', + output: { + file: path.resolve('./memory', memoryPkg['esm2017']), + format: 'es', + sourcemap: true + }, + plugins: util.es2017Plugins('browser', /* mangled= */ true), + external: util.resolveBrowserExterns + }, + { + input: path.resolve('./memory', memoryPkg['esm2017']), + output: { + file: path.resolve('./memory', memoryPkg.module), + format: 'es', + sourcemap: true + }, + plugins: util.es2017ToEs5Plugins(/* mangled= */ true), + external: util.resolveBrowserExterns + }, + { + input: path.resolve('./memory', memoryPkg['esm2017']), + output: { + file: path.resolve('./memory', memoryPkg.browser), + format: 'cjs', + sourcemap: true + }, + plugins: util.es2017ToEs5Plugins(/* mangled= */ true), + external: util.resolveBrowserExterns + } +]; diff --git a/packages/firestore/rollup.config.es2017.js b/packages/firestore/rollup.config.es2017.js deleted file mode 100644 index e7ec341b975..00000000000 --- a/packages/firestore/rollup.config.es2017.js +++ /dev/null @@ -1,177 +0,0 @@ -/** - * @license - * Copyright 2018 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as path from 'path'; - -import json from 'rollup-plugin-json'; -import alias from '@rollup/plugin-alias'; -import typescriptPlugin from 'rollup-plugin-typescript2'; -import replace from 'rollup-plugin-replace'; -import copy from 'rollup-plugin-copy-assets'; -import typescript from 'typescript'; -import { terser } from 'rollup-plugin-terser'; - -import pkg from './package.json'; -import memoryPkg from './memory/package.json'; - -const util = require('./rollup.shared'); - -// Firestore is released in a number of different build configurations: -// - Browser builds that support persistence in ES5 CJS and ES5 ESM formats and -// ES2017 in ESM format. -// - In-memory Browser builds that support persistence in ES5 CJS and ES5 ESM -// formats and ES2017 in ESM format. -// - A NodeJS build that supports persistence (to be used with an IndexedDb -// shim) -// - A in-memory only NodeJS build -// -// The in-memory builds are roughly 130 KB smaller, but throw an exception -// for calls to `enablePersistence()` or `clearPersistence()`. -// -// We use two different rollup pipelines to take advantage of tree shaking, -// as Rollup does not support tree shaking for Typescript classes transpiled -// down to ES5 (see https://bit.ly/340P23U). The build pipeline in this file -// produces tree-shaken ES2017 builds that are consumed by the ES5 builds in -// `rollup.config.es.js`. -// -// All browser builds rely on Terser's property name mangling to reduce code -// size. -// -// See https://g3doc/firebase/jscore/g3doc/contributing/builds.md -// for a description of the various JavaScript formats used in our SDKs. - -// MARK: Browser builds - -const browserBuildPlugins = [ - alias(util.generateAliasConfig('browser')), - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, - clean: true, - transformers: [util.removeAssertAndPrefixInternalTransformer] - }), - json({ preferConst: true }), - terser(util.manglePrivatePropertiesOptions) -]; - -const browserBuilds = [ - // Persistence build - { - input: 'index.ts', - output: { - file: pkg.esm2017, - format: 'es', - sourcemap: true - }, - plugins: browserBuildPlugins, - external: util.resolveBrowserExterns - }, - // Memory-only build - { - input: 'index.memory.ts', - output: { - file: path.resolve('./memory', memoryPkg.esm2017), - format: 'es', - sourcemap: true - }, - plugins: browserBuildPlugins, - external: util.resolveBrowserExterns - } -]; - -const reactNativeBuildPlugins = [ - alias(util.generateAliasConfig('rn')), - ...browserBuildPlugins.slice(1) -]; - -const reactNativeBuilds = [ - // Persistence build - { - input: 'index.rn.ts', - output: { - file: pkg['react-native'], - format: 'es', - sourcemap: true - }, - plugins: reactNativeBuildPlugins, - external: util.resolveBrowserExterns - }, - // Memory-only build - { - input: 'index.rn.memory.ts', - output: { - file: path.resolve('./memory', memoryPkg['react-native']), - format: 'es', - sourcemap: true - }, - plugins: reactNativeBuildPlugins, - external: util.resolveBrowserExterns - } -]; - -// MARK: Node builds - -const nodeBuildPlugins = [ - alias(util.generateAliasConfig('node')), - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, - clean: true, - transformers: [util.removeAssertTransformer] - }), - json(), - // Needed as we also use the *.proto files - copy({ - assets: ['./src/protos'] - }), - replace({ - 'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos') - }) -]; - -const nodeBuilds = [ - // Persistence build - { - input: 'index.node.ts', - output: [{ file: pkg['main-esm2017'], format: 'es', sourcemap: true }], - plugins: nodeBuildPlugins, - external: util.resolveNodeExterns - }, - // Memory-only build - { - input: 'index.node.memory.ts', - output: [ - { - file: path.resolve('./memory', memoryPkg['main-esm2017']), - format: 'es', - sourcemap: true - } - ], - plugins: nodeBuildPlugins, - external: util.resolveNodeExterns - } -]; - -export default [...browserBuilds, ...reactNativeBuilds, ...nodeBuilds]; diff --git a/packages/firestore/rollup.config.es5.js b/packages/firestore/rollup.config.es5.js deleted file mode 100644 index 926307fd7a3..00000000000 --- a/packages/firestore/rollup.config.es5.js +++ /dev/null @@ -1,120 +0,0 @@ -/** - * @license - * Copyright 2018 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as path from 'path'; - -import typescriptPlugin from 'rollup-plugin-typescript2'; -import sourcemaps from 'rollup-plugin-sourcemaps'; -import typescript from 'typescript'; -import { terser } from 'rollup-plugin-terser'; - -import pkg from './package.json'; -import memoryPkg from './memory/package.json'; - -const util = require('./rollup.shared'); - -// This file defines the second rollup pipeline and transpiles the ES2017 SDK -// into ES5 code. By splitting the build process into two independent build -// pipelines, we take advantage of tree shaking in ES2017 builds even for -// language levels that don't support tree shaking. - -const browserPlugins = [ - typescriptPlugin({ - typescript, - compilerOptions: { - allowJs: true - }, - include: ['dist/*.js'] - }), - terser({ - output: { - comments: 'all', - beautify: true - }, - mangle: true - }), - sourcemaps() -]; - -const nodePlugins = [ - typescriptPlugin({ - typescript, - compilerOptions: { - allowJs: true - }, - include: ['dist/*.js'] - }), - sourcemaps() -]; - -const browserBuilds = [ - { - input: pkg.esm2017, - output: { file: pkg.module, format: 'es', sourcemap: true }, - plugins: browserPlugins, - external: util.resolveBrowserExterns - }, - { - input: path.resolve('./memory', memoryPkg.esm2017), - output: { - file: path.resolve('./memory', memoryPkg.module), - format: 'es', - sourcemap: true - }, - plugins: browserPlugins, - external: util.resolveBrowserExterns - }, - { - input: pkg.esm2017, - output: { file: pkg.browser, format: 'cjs', sourcemap: true }, - plugins: browserPlugins, - external: util.resolveBrowserExterns - }, - { - input: path.resolve('./memory', memoryPkg.esm2017), - output: { - file: path.resolve('./memory', memoryPkg.browser), - format: 'cjs', - sourcemap: true - }, - plugins: browserPlugins, - external: util.resolveBrowserExterns - } -]; - -const nodeBuilds = [ - { - input: pkg['main-esm2017'], - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], - plugins: nodePlugins, - external: util.resolveNodeExterns - }, - { - input: path.resolve('./memory', memoryPkg['main-esm2017']), - output: [ - { - file: path.resolve('./memory', memoryPkg.main), - format: 'cjs', - sourcemap: true - } - ], - plugins: nodePlugins, - external: util.resolveNodeExterns - } -]; - -export default [...browserBuilds, ...nodeBuilds]; diff --git a/packages/firestore/rollup.config.exp.js b/packages/firestore/rollup.config.exp.js index a46968d67f8..aeafef8b93b 100644 --- a/packages/firestore/rollup.config.exp.js +++ b/packages/firestore/rollup.config.exp.js @@ -15,6 +15,7 @@ * limitations under the License. */ +import tmp from 'tmp'; import json from 'rollup-plugin-json'; import alias from '@rollup/plugin-alias'; import typescriptPlugin from 'rollup-plugin-typescript2'; @@ -36,7 +37,7 @@ const nodePlugins = [ target: 'es2017' } }, - clean: true, + cacheDir: tmp.dirSync(), abortOnError: false, transformers: [util.removeAssertTransformer, importPathTransformer] }), @@ -51,7 +52,7 @@ const browserPlugins = [ target: 'es2017' } }, - clean: true, + cacheDir: tmp.dirSync(), abortOnError: false, transformers: [ util.removeAssertAndPrefixInternalTransformer, diff --git a/packages/firestore/rollup.config.lite.js b/packages/firestore/rollup.config.lite.js index a808eb040d1..1e49ddbb1a2 100644 --- a/packages/firestore/rollup.config.lite.js +++ b/packages/firestore/rollup.config.lite.js @@ -15,6 +15,7 @@ * limitations under the License. */ +import tmp from 'tmp'; import path from 'path'; import json from 'rollup-plugin-json'; import alias from '@rollup/plugin-alias'; @@ -36,7 +37,7 @@ const nodePlugins = [ target: 'es2017' } }, - clean: true, + cacheDir: tmp.dirSync(), abortOnError: false, transformers: [util.removeAssertTransformer, importPathTransformer] }), @@ -51,7 +52,7 @@ const browserPlugins = [ target: 'es2017' } }, - clean: true, + cacheDir: tmp.dirSync(), abortOnError: false, transformers: [ util.removeAssertAndPrefixInternalTransformer, diff --git a/packages/firestore/rollup.config.node.js b/packages/firestore/rollup.config.node.js new file mode 100644 index 00000000000..9741b87e773 --- /dev/null +++ b/packages/firestore/rollup.config.node.js @@ -0,0 +1,50 @@ +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import replace from 'rollup-plugin-replace'; +import copy from 'rollup-plugin-copy-assets'; +import pkg from './package.json'; + +const util = require('./rollup.shared'); + +export default [ + { + input: 'index.node.ts', + output: { + file: pkg['main-esm2017'], + format: 'es', + sourcemap: true + }, + plugins: [ + ...util.es2017Plugins('node'), + // Needed as we also use the *.proto files + copy({ + assets: ['./src/protos'] + }), + replace({ + 'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos') + }) + ], + external: util.resolveNodeExterns + }, + { + input: pkg['main-esm2017'], + output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], + plugins: util.es2017ToEs5Plugins(), + external: util.resolveNodeExterns + } +]; diff --git a/packages/firestore/rollup.config.node.memory.js b/packages/firestore/rollup.config.node.memory.js new file mode 100644 index 00000000000..b69df1390e2 --- /dev/null +++ b/packages/firestore/rollup.config.node.memory.js @@ -0,0 +1,55 @@ +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as path from 'path'; +import replace from 'rollup-plugin-replace'; +import copy from 'rollup-plugin-copy-assets'; +import memoryPkg from './memory/package.json'; + +const util = require('./rollup.shared'); + +export default [ + { + input: 'index.node.memory.ts', + output: { + file: path.resolve('./memory', memoryPkg['main-esm2017']), + format: 'es', + sourcemap: true + }, + plugins: [ + ...util.es2017Plugins('node'), + // Needed as we also use the *.proto files + copy({ + assets: ['./src/protos'] + }), + replace({ + 'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos') + }) + ], + external: util.resolveNodeExterns + }, + { + input: path.resolve('./memory', memoryPkg['main-esm2017']), + output: { + file: path.resolve('./memory', memoryPkg.main), + format: 'cjs', + sourcemap: true + }, + plugins: util.es2017ToEs5Plugins(), + external: util.resolveNodeExterns + } +]; diff --git a/packages/firestore/rollup.config.rn.js b/packages/firestore/rollup.config.rn.js new file mode 100644 index 00000000000..72a83bd92a3 --- /dev/null +++ b/packages/firestore/rollup.config.rn.js @@ -0,0 +1,31 @@ +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import pkg from './package.json'; + +const util = require('./rollup.shared'); + +export default { + input: 'index.rn.ts', + output: { + file: pkg['react-native'], + format: 'es', + sourcemap: true + }, + plugins: util.es2017Plugins('rn', /* mangled= */ true), + external: util.resolveBrowserExterns +}; diff --git a/packages/firestore/rollup.config.rn.memory.js b/packages/firestore/rollup.config.rn.memory.js new file mode 100644 index 00000000000..f6b53cfe179 --- /dev/null +++ b/packages/firestore/rollup.config.rn.memory.js @@ -0,0 +1,32 @@ +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as path from 'path'; +import memoryPkg from './memory/package.json'; + +const util = require('./rollup.shared'); + +export default { + input: 'index.rn.memory.ts', + output: { + file: path.resolve('./memory', memoryPkg['react-native']), + format: 'es', + sourcemap: true + }, + plugins: util.es2017Plugins('rn', /* mangled= */ true), + external: util.resolveBrowserExterns +}; diff --git a/packages/firestore/rollup.shared.js b/packages/firestore/rollup.shared.js index 00eed3ba349..c41b46a1f1c 100644 --- a/packages/firestore/rollup.shared.js +++ b/packages/firestore/rollup.shared.js @@ -15,7 +15,14 @@ * limitations under the License. */ +const tmp = require('tmp'); +const json = require('rollup-plugin-json'); +const alias = require('@rollup/plugin-alias'); +const typescriptPlugin = require('rollup-plugin-typescript2'); +const typescript = require('typescript'); +const { terser } = require('rollup-plugin-terser'); const path = require('path'); +const sourcemaps = require('rollup-plugin-sourcemaps'); const { renameInternals } = require('./scripts/rename-internals'); const { extractPublicIdentifiers } = require('./scripts/extract-api'); @@ -24,12 +31,38 @@ const { removeAsserts } = require('./scripts/remove-asserts'); const { externs } = require('./externs.json'); const pkg = require('./package.json'); +// This file contains shared utilities for Firestore's rollup builds. + +// Firestore is released in a number of different build configurations: +// - Browser builds that support persistence in ES5 CJS and ES5 ESM formats and +// ES2017 in ESM format. +// - In-memory Browser builds that support persistence in ES5 CJS and ES5 ESM +// formats and ES2017 in ESM format. +// - A NodeJS build that supports persistence (to be used with an IndexedDb +// shim) +// - A in-memory only NodeJS build +// +// The in-memory builds are roughly 130 KB smaller, but throw an exception +// for calls to `enablePersistence()` or `clearPersistence()`. +// +// We use two different rollup pipelines to take advantage of tree shaking, +// as Rollup does not support tree shaking for Typescript classes transpiled +// down to ES5 (see https://bit.ly/340P23U). The build pipeline in this file +// produces tree-shaken ES2017 builds that are consumed by the ES5 builds in +// `rollup.config.es.js`. +// +// All browser builds rely on Terser's property name mangling to reduce code +// size. +// +// See https://g3doc/firebase/jscore/g3doc/contributing/builds.md +// for a description of the various JavaScript formats used in our SDKs. + /** * Returns an replacement configuration for `@rollup/plugin-alias` that replaces * references to platform-specific files with implementations for the provided * target platform. */ -exports.generateAliasConfig = function (platform) { +function generateAliasConfig(platform) { return { entries: [ { @@ -38,7 +71,8 @@ exports.generateAliasConfig = function (platform) { } ] }; -}; +} +exports.generateAliasConfig = generateAliasConfig; const browserDeps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) @@ -63,16 +97,17 @@ const publicIdentifiers = extractPublicIdentifiers(externsPaths); * Transformers that remove calls to `debugAssert` and messages for 'fail` and * `hardAssert`. */ -exports.removeAssertTransformer = service => ({ +const removeAssertTransformer = service => ({ before: [removeAsserts(service.getProgram())], after: [] }); +exports.removeAssertTransformer = removeAssertTransformer; /** * Transformers that remove calls to `debugAssert`, messages for 'fail` and * `hardAssert` and appends a __PRIVATE_ prefix to all internal symbols. */ -exports.removeAssertAndPrefixInternalTransformer = service => ({ +const removeAssertAndPrefixInternalTransformer = service => ({ before: [ removeAsserts(service.getProgram()), renameInternals(service.getProgram(), { @@ -82,11 +117,12 @@ exports.removeAssertAndPrefixInternalTransformer = service => ({ ], after: [] }); +exports.removeAssertAndPrefixInternalTransformer = removeAssertAndPrefixInternalTransformer; /** * Terser options that mangle all properties prefixed with __PRIVATE_. */ -exports.manglePrivatePropertiesOptions = { +const manglePrivatePropertiesOptions = { output: { comments: 'all', beautify: true @@ -97,3 +133,72 @@ exports.manglePrivatePropertiesOptions = { } } }; +exports.manglePrivatePropertiesOptions = manglePrivatePropertiesOptions; + +exports.es2017Plugins = function (platform, mangled = false) { + if (mangled) { + return [ + alias(generateAliasConfig(platform)), + typescriptPlugin({ + typescript, + tsconfigOverride: { + compilerOptions: { + target: 'es2017' + } + }, + cacheDir: tmp.dirSync(), + transformers: [removeAssertAndPrefixInternalTransformer] + }), + json({ preferConst: true }), + terser(manglePrivatePropertiesOptions) + ]; + } else { + return [ + alias(generateAliasConfig(platform)), + typescriptPlugin({ + typescript, + tsconfigOverride: { + compilerOptions: { + target: 'es2017' + } + }, + cacheDir: tmp.dirSync(), + transformers: [removeAssertTransformer] + }), + json({ preferConst: true }) + ]; + } +}; + +exports.es2017ToEs5Plugins = function (mangled = false) { + if (mangled) { + return [ + typescriptPlugin({ + typescript, + compilerOptions: { + allowJs: true + }, + include: ['dist/*.js'] + }), + terser({ + output: { + comments: 'all', + beautify: true + }, + mangle: true + }), + sourcemaps() + ]; + } else { + return [ + typescriptPlugin({ + typescript, + compilerOptions: { + allowJs: true + }, + include: ['dist/*.js'] + }), + sourcemaps() + ]; + } +};