-
Notifications
You must be signed in to change notification settings - Fork 930
Pre-process all ES5 builds #2840
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
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0027ac1
Pre-process all ES3 builds
schmidt-sebastian 2ac59f1
Fix build
schmidt-sebastian 3e176e4
Fix up
schmidt-sebastian 9fd0e0d
Mangling for Browser builds
schmidt-sebastian 3545adf
Better docs
schmidt-sebastian 3a26d5e
Review
schmidt-sebastian b5653a7
Add Terser back
schmidt-sebastian 8926cd1
Review
schmidt-sebastian 59744b1
Merge branch 'master' into mrschmidt/splitrollup
schmidt-sebastian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"author": "Firebase <[email protected]> (https://firebase.google.com/)", | ||
"scripts": { | ||
"prebuild": "tsc -d --downlevelIteration --declarationDir dist/lib --emitDeclarationOnly && tsc -m es2015 --moduleResolution node scripts/*.ts ", | ||
"build": "rollup -c", | ||
"build": "rollup -c rollup.config.es2017.js && rollup -c rollup.config.es5.js", | ||
"build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build", | ||
"build:console": "node tools/console.build.js", | ||
"predev": "yarn prebuild", | ||
|
@@ -26,6 +26,7 @@ | |
"prepare": "yarn build" | ||
}, | ||
"main": "dist/index.node.cjs.js", | ||
"main-esm2017": "dist/index.node.esm2017.js", | ||
"browser": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"esm2017": "dist/index.esm2017.js", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/** | ||
* @license | ||
* Copyright 2018 Google Inc. | ||
* | ||
* 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 { resolveNodeExterns, resolveBrowserExterns } from './rollup.shared'; | ||
|
||
import pkg from './package.json'; | ||
import memoryPkg from './memory/package.json'; | ||
|
||
// 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'] | ||
}), | ||
terser({ | ||
output: { | ||
comments: 'all', | ||
beautify: true | ||
}, | ||
mangle: false | ||
}), | ||
sourcemaps() | ||
]; | ||
|
||
const browserBuilds = [ | ||
{ | ||
input: pkg.esm2017, | ||
output: { file: pkg.module, format: 'es', sourcemap: true }, | ||
plugins: browserPlugins, | ||
external: resolveBrowserExterns | ||
}, | ||
{ | ||
input: path.resolve('./memory', memoryPkg.esm2017), | ||
output: { | ||
file: path.resolve('./memory', memoryPkg.module), | ||
format: 'es', | ||
sourcemap: true | ||
}, | ||
plugins: browserPlugins, | ||
external: resolveBrowserExterns | ||
}, | ||
{ | ||
input: pkg.esm2017, | ||
output: { file: pkg.browser, format: 'cjs', sourcemap: true }, | ||
plugins: browserPlugins, | ||
external: resolveBrowserExterns | ||
}, | ||
{ | ||
input: path.resolve('./memory', memoryPkg.esm2017), | ||
output: { | ||
file: path.resolve('./memory', memoryPkg.browser), | ||
format: 'cjs', | ||
sourcemap: true | ||
}, | ||
plugins: browserPlugins, | ||
external: resolveBrowserExterns | ||
} | ||
]; | ||
|
||
const nodeBuilds = [ | ||
{ | ||
input: pkg['main-esm2017'], | ||
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], | ||
plugins: nodePlugins, | ||
external: resolveNodeExterns | ||
}, | ||
{ | ||
input: path.resolve('./memory', memoryPkg['main-esm2017']), | ||
output: [ | ||
{ | ||
file: path.resolve('./memory', memoryPkg.main), | ||
format: 'cjs', | ||
sourcemap: true | ||
} | ||
], | ||
plugins: nodePlugins, | ||
external: resolveNodeExterns | ||
} | ||
]; | ||
|
||
export default [...browserBuilds, ...nodeBuilds]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is not accurate. rollup can tree shake ES5 builds as long as they are in the ESM format. The limitation is specific to the Typescript classes compiled down to ES5.
Also do you mean
post-tree shaken ES2017
builds? IIUC, treeshaking is done in this phase, the second phase just changes the module format.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.
Updated the comment. I did mean "pre tree-shaken", as in "these builds are already tree shaken", which is the same as "post tree-shaken". Hence, I dropped the term.