mirror of
https://github.com/hanzoai/firebase-js-sdk.git
synced 2026-09-24 16:59:10 +00:00
268 lines
7.4 KiB
JavaScript
268 lines
7.4 KiB
JavaScript
/**
|
|
* @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 tmp from 'tmp';
|
|
import path from 'path';
|
|
import json from '@rollup/plugin-json';
|
|
import alias from '@rollup/plugin-alias';
|
|
import typescriptPlugin from 'rollup-plugin-typescript2';
|
|
import typescript from 'typescript';
|
|
import sourcemaps from 'rollup-plugin-sourcemaps';
|
|
import replace from 'rollup-plugin-replace';
|
|
import terser from '@rollup/plugin-terser';
|
|
|
|
import * as util from './rollup.shared.cjs';
|
|
|
|
import { generateBuildTargetReplaceConfig } from '../../scripts/build/rollup_replace_build_target.js';
|
|
|
|
const nodePlugins = [
|
|
typescriptPlugin({
|
|
typescript,
|
|
cacheDir: tmp.dirSync().name,
|
|
abortOnError: true,
|
|
transformers: [util.removeAssertTransformer]
|
|
}),
|
|
json({ preferConst: true })
|
|
];
|
|
|
|
const browserPlugins = [
|
|
typescriptPlugin({
|
|
typescript,
|
|
cacheDir: tmp.dirSync().name,
|
|
abortOnError: true,
|
|
transformers: [util.removeAssertAndPrefixInternalTransformer]
|
|
}),
|
|
json({ preferConst: true }),
|
|
terser(util.manglePrivatePropertiesOptions),
|
|
util.cleanupNameCache(util.manglePrivatePropertiesOptions.nameCache)
|
|
];
|
|
|
|
const allBuilds = [
|
|
// Workaround for https://github.com/rollup/plugins/issues/1970
|
|
// We invoke this intermediate browser build twice. The first
|
|
// invocation will not properly mangle property names because of the
|
|
// rollup/plugin-terser issue #1970, however it will output a nameCache
|
|
// mapping all of the mangled names to new names. The second invocation
|
|
// will use the nameCache from the first, and consistently mangle
|
|
// all property names.
|
|
//
|
|
// This is the first invocation of the intermediate browser build.
|
|
// It must run before any other build using `browserPlugins`.
|
|
// TODO Remove this build when https://github.com/rollup/plugins/issues/1970 is fixed.
|
|
{
|
|
input: ['./lite/index.ts', './lite/pipelines/pipelines.ts'],
|
|
output: {
|
|
dir: 'dist/intermediate/lite/',
|
|
entryFileNames: '[name].browser.js',
|
|
chunkFileNames: 'common.browser.js',
|
|
format: 'es',
|
|
sourcemap: true
|
|
},
|
|
plugins: [
|
|
alias(util.generateAliasConfig('browser_lite')),
|
|
...browserPlugins,
|
|
// setting it to empty string because browser is the default env
|
|
replace({
|
|
'__RUNTIME_ENV__': ''
|
|
})
|
|
],
|
|
external: util.resolveBrowserExterns,
|
|
treeshake: {
|
|
moduleSideEffects: false
|
|
}
|
|
},
|
|
// Intermediate Node ESM build without build target reporting
|
|
// this is an intermediate build used to generate the actual esm and cjs builds
|
|
// which add build target reporting
|
|
{
|
|
input: ['./lite/index.ts', './lite/pipelines/pipelines.ts'],
|
|
output: {
|
|
dir: 'dist/intermediate/lite/',
|
|
entryFileNames: '[name].node.mjs',
|
|
chunkFileNames: 'common-[hash].node.mjs',
|
|
format: 'es',
|
|
sourcemap: true
|
|
},
|
|
plugins: [
|
|
alias(util.generateAliasConfig('node_lite')),
|
|
...nodePlugins,
|
|
replace({
|
|
'__RUNTIME_ENV__': 'node'
|
|
})
|
|
],
|
|
external: util.resolveNodeExterns,
|
|
treeshake: {
|
|
moduleSideEffects: false
|
|
},
|
|
onwarn: util.onwarn
|
|
},
|
|
// Node CJS build
|
|
{
|
|
input: [
|
|
'dist/intermediate/lite/index.node.mjs',
|
|
'dist/intermediate/lite/pipelines.node.mjs'
|
|
],
|
|
output: {
|
|
dir: 'dist/lite/',
|
|
entryFileNames: '[name].cjs.js',
|
|
chunkFileNames: 'common-[hash].node.cjs.js',
|
|
format: 'cjs',
|
|
esModule: true,
|
|
sourcemap: true
|
|
},
|
|
plugins: [
|
|
typescriptPlugin({
|
|
typescript,
|
|
compilerOptions: {
|
|
allowJs: true
|
|
},
|
|
include: ['dist/lite/*.js']
|
|
}),
|
|
json(),
|
|
sourcemaps(),
|
|
replace(generateBuildTargetReplaceConfig('cjs', 2020))
|
|
],
|
|
external: util.resolveNodeExterns,
|
|
treeshake: {
|
|
moduleSideEffects: false
|
|
}
|
|
},
|
|
// Node ESM build
|
|
{
|
|
input: [
|
|
'dist/intermediate/lite/index.node.mjs',
|
|
'dist/intermediate/lite/pipelines.node.mjs'
|
|
],
|
|
output: {
|
|
dir: 'dist/lite/',
|
|
entryFileNames: '[name].mjs',
|
|
chunkFileNames: 'common-[hash].node.mjs',
|
|
format: 'es',
|
|
sourcemap: true
|
|
},
|
|
plugins: [
|
|
sourcemaps(),
|
|
replace(generateBuildTargetReplaceConfig('esm', 2020))
|
|
],
|
|
external: util.resolveNodeExterns,
|
|
treeshake: {
|
|
moduleSideEffects: false
|
|
}
|
|
},
|
|
// This is the second invocation of the intermediate browser build.
|
|
// Keep this build when https://github.com/rollup/plugins/issues/1970 is fixed.
|
|
//
|
|
// Intermediate browser build without build target reporting
|
|
// this is an intermediate build used to generate the actual esm and cjs builds
|
|
// which add build target reporting
|
|
{
|
|
input: ['./lite/index.ts', './lite/pipelines/pipelines.ts'],
|
|
output: {
|
|
dir: 'dist/intermediate/lite/',
|
|
entryFileNames: '[name].browser.js',
|
|
chunkFileNames: 'common.browser.js',
|
|
format: 'es',
|
|
sourcemap: true
|
|
},
|
|
plugins: [
|
|
alias(util.generateAliasConfig('browser_lite')),
|
|
...browserPlugins,
|
|
// setting it to empty string because browser is the default env
|
|
replace({
|
|
'__RUNTIME_ENV__': ''
|
|
})
|
|
],
|
|
external: util.resolveBrowserExterns,
|
|
treeshake: {
|
|
moduleSideEffects: false
|
|
}
|
|
},
|
|
// Convert es2020 build to CJS
|
|
{
|
|
input: [
|
|
'dist/intermediate/lite/index.browser.js',
|
|
'dist/intermediate/lite/pipelines.browser.js'
|
|
],
|
|
output: [
|
|
{
|
|
dir: 'dist/lite/',
|
|
entryFileNames: '[name].cjs.js',
|
|
chunkFileNames: 'common-[hash].cjs.js',
|
|
format: 'es',
|
|
sourcemap: true
|
|
}
|
|
],
|
|
plugins: [
|
|
sourcemaps(),
|
|
replace(generateBuildTargetReplaceConfig('cjs', 2020))
|
|
],
|
|
external: util.resolveBrowserExterns,
|
|
treeshake: {
|
|
moduleSideEffects: false
|
|
}
|
|
},
|
|
// Browser es2020 build
|
|
{
|
|
input: [
|
|
'dist/intermediate/lite/index.browser.js',
|
|
'dist/intermediate/lite/pipelines.browser.js'
|
|
],
|
|
output: [
|
|
{
|
|
dir: 'dist/lite/',
|
|
entryFileNames: '[name].esm.js',
|
|
chunkFileNames: 'common-[hash].esm.js',
|
|
format: 'es',
|
|
sourcemap: true
|
|
}
|
|
],
|
|
plugins: [
|
|
sourcemaps(),
|
|
replace(generateBuildTargetReplaceConfig('esm', 2020))
|
|
],
|
|
external: util.resolveBrowserExterns,
|
|
treeshake: {
|
|
moduleSideEffects: false
|
|
}
|
|
},
|
|
// RN build
|
|
{
|
|
input: ['./lite/index.ts', './lite/pipelines/pipelines.ts'],
|
|
output: {
|
|
dir: 'dist/lite/',
|
|
entryFileNames: '[name].rn.esm.js',
|
|
chunkFileNames: 'common-[hash].rn.esm.js',
|
|
format: 'es',
|
|
sourcemap: true
|
|
},
|
|
plugins: [
|
|
alias(util.generateAliasConfig('rn_lite')),
|
|
...browserPlugins,
|
|
replace({
|
|
...generateBuildTargetReplaceConfig('esm', 2020),
|
|
'__RUNTIME_ENV__': 'rn'
|
|
})
|
|
],
|
|
external: util.resolveBrowserExterns,
|
|
treeshake: {
|
|
moduleSideEffects: false
|
|
}
|
|
}
|
|
];
|
|
|
|
export default allBuilds;
|