Skip to content

Commit 58a2641

Browse files
committed
use shared rollup config to reduce duplication
1 parent 5380a81 commit 58a2641

File tree

11 files changed

+297
-163
lines changed

11 files changed

+297
-163
lines changed

packages-exp/functions-exp/rollup.config.js

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
import json from 'rollup-plugin-json';
1919
import typescriptPlugin from 'rollup-plugin-typescript2';
2020
import typescript from 'typescript';
21-
import pkg from './package.json';
22-
23-
const deps = Object.keys(
24-
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
25-
);
21+
import { es2017BuildsNoPlugin, es5BuildsNoPlugin } from './rollup.shared';
2622

2723
/**
2824
* ES5 Builds
@@ -34,27 +30,14 @@ const es5BuildPlugins = [
3430
json()
3531
];
3632

37-
const es5Builds = [
38-
/**
39-
* Browser Builds
40-
*/
41-
{
42-
input: 'src/index.ts',
43-
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
44-
plugins: es5BuildPlugins,
45-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
46-
},
47-
/**
48-
* Node.js Build
49-
*/
50-
{
51-
input: 'src/index.node.ts',
52-
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
53-
plugins: es5BuildPlugins,
54-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
55-
}
56-
];
33+
const es5Builds = es5BuildsNoPlugin.map(build => ({
34+
...build,
35+
plugins: es5BuildPlugins
36+
}));
5737

38+
/**
39+
* ES2017 Builds
40+
*/
5841
const es2017BuildPlugins = [
5942
typescriptPlugin({
6043
typescript,
@@ -67,23 +50,9 @@ const es2017BuildPlugins = [
6750
json({ preferConst: true })
6851
];
6952

70-
/**
71-
* ES2017 Builds
72-
*/
73-
const es2017Builds = [
74-
{
75-
/**
76-
* Browser Build
77-
*/
78-
input: 'src/index.ts',
79-
output: {
80-
file: pkg.esm2017,
81-
format: 'es',
82-
sourcemap: true
83-
},
84-
plugins: es2017BuildPlugins,
85-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
86-
}
87-
];
53+
const es2017Builds = es2017BuildsNoPlugin.map(build => ({
54+
...build,
55+
plugins: es2017BuildPlugins
56+
}));
8857

8958
export default [...es5Builds, ...es2017Builds];

packages-exp/functions-exp/rollup.config.release.js

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@
1818
import typescriptPlugin from 'rollup-plugin-typescript2';
1919
import typescript from 'typescript';
2020
import json from 'rollup-plugin-json';
21-
import pkg from './package.json';
2221
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';
23-
24-
const deps = Object.keys(
25-
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
26-
);
22+
import { es2017BuildsNoPlugin, es5BuildsNoPlugin } from './rollup.shared';
2723

2824
/**
2925
* ES5 Builds
@@ -38,32 +34,13 @@ const es5BuildPlugins = [
3834
json()
3935
];
4036

41-
const es5Builds = [
42-
/**
43-
* Browser Builds
44-
*/
45-
{
46-
input: 'src/index.ts',
47-
output: [{ file: pkg.browser, format: 'es', sourcemap: true }],
48-
plugins: es5BuildPlugins,
49-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
50-
treeshake: {
51-
moduleSideEffects: false
52-
}
53-
},
54-
/**
55-
* Node.js Build
56-
*/
57-
{
58-
input: 'src/index.ts',
59-
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
60-
plugins: es5BuildPlugins,
61-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
62-
treeshake: {
63-
moduleSideEffects: false
64-
}
37+
const es5Builds = es5BuildsNoPlugin.map(build => ({
38+
...build,
39+
plugins: es5BuildPlugins,
40+
treeshake: {
41+
moduleSideEffects: false
6542
}
66-
];
43+
}));
6744

6845
/**
6946
* ES2017 Builds
@@ -85,23 +62,12 @@ const es2017BuildPlugins = [
8562
})
8663
];
8764

88-
const es2017Builds = [
89-
/**
90-
* Browser Builds
91-
*/
92-
{
93-
input: 'src/index.ts',
94-
output: {
95-
file: pkg.esm2017,
96-
format: 'es',
97-
sourcemap: true
98-
},
99-
plugins: es2017BuildPlugins,
100-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
101-
treeshake: {
102-
moduleSideEffects: false
103-
}
65+
const es2017Builds = es2017BuildsNoPlugin.map(build => ({
66+
...build,
67+
plugins: es2017BuildPlugins,
68+
treeshake: {
69+
moduleSideEffects: false
10470
}
105-
];
71+
}));
10672

10773
export default [...es5Builds, ...es2017Builds];
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license
3+
* Copyright 2018 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
import pkg from './package.json';
18+
19+
const deps = Object.keys(
20+
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
21+
);
22+
23+
export const es5BuildsNoPlugin = [
24+
/**
25+
* Browser Builds
26+
*/
27+
{
28+
input: 'src/index.ts',
29+
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
30+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
31+
},
32+
/**
33+
* Node.js Build
34+
*/
35+
{
36+
input: 'src/index.node.ts',
37+
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
38+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
39+
}
40+
];
41+
42+
/**
43+
* ES2017 Builds
44+
*/
45+
export const es2017BuildsNoPlugin = [
46+
{
47+
/**
48+
* Browser Build
49+
*/
50+
input: 'src/index.ts',
51+
output: {
52+
file: pkg.esm2017,
53+
format: 'es',
54+
sourcemap: true
55+
},
56+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
57+
}
58+
];

packages-exp/installations-exp/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1616
"build": "rollup -c && yarn api-report",
1717
"build:deps": "lerna run --scope @firebase/installations-exp --include-dependencies build",
18+
"build:release": "rollup -c rollup.config.release.js && yarn api-report",
1819
"dev": "rollup -c -w",
1920
"test": "yarn type-check && yarn test:karma && yarn lint",
2021
"test:ci": "node ../../scripts/run_tests_in_ci.js",
@@ -24,7 +25,7 @@
2425
"serve": "yarn serve:build && yarn serve:host",
2526
"serve:build": "rollup -c test-app/rollup.config.js",
2627
"serve:host": "http-server -c-1 test-app",
27-
"prepare": "yarn build",
28+
"prepare": "yarn build:release",
2829
"api-report": "api-extractor run --local --verbose",
2930
"predoc": "node ../../scripts/exp/remove-exp.js temp",
3031
"doc": "api-documenter markdown --input temp --output docs",

packages-exp/installations-exp/rollup.config.js

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,17 @@
1717

1818
import json from 'rollup-plugin-json';
1919
import typescriptPlugin from 'rollup-plugin-typescript2';
20-
import pkg from './package.json';
2120
import typescript from 'typescript';
2221

23-
const deps = Object.keys({ ...pkg.peerDependencies, ...pkg.dependencies });
24-
2522
/**
2623
* ES5 Builds
2724
*/
2825
const es5BuildPlugins = [typescriptPlugin({ typescript }), json()];
2926

30-
const es5Builds = [
31-
{
32-
input: 'src/index.ts',
33-
output: [
34-
{ file: pkg.main, format: 'cjs', sourcemap: true },
35-
{ file: pkg.module, format: 'es', sourcemap: true }
36-
],
37-
plugins: es5BuildPlugins,
38-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
39-
}
40-
];
27+
const es5Builds = es5BuildsNoPlugin.map(build => ({
28+
...build,
29+
plugins: es5BuildPlugins
30+
}));
4131

4232
/**
4333
* ES2017 Builds
@@ -54,17 +44,9 @@ const es2017BuildPlugins = [
5444
json({ preferConst: true })
5545
];
5646

57-
const es2017Builds = [
58-
{
59-
input: 'src/index.ts',
60-
output: {
61-
file: pkg.esm2017,
62-
format: 'es',
63-
sourcemap: true
64-
},
65-
plugins: es2017BuildPlugins,
66-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
67-
}
68-
];
47+
const es2017Builds = es2017BuildsNoPlugin.map(build => ({
48+
...build,
49+
plugins: es2017BuildPlugins
50+
}));
6951

7052
export default [...es5Builds, ...es2017Builds];
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import json from 'rollup-plugin-json';
19+
import typescriptPlugin from 'rollup-plugin-typescript2';
20+
import typescript from 'typescript';
21+
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';
22+
import { es2017BuildsNoPlugin, es5BuildsNoPlugin } from './rollup.shared';
23+
24+
/**
25+
* ES5 Builds
26+
*/
27+
const es5BuildPlugins = [
28+
typescriptPlugin({
29+
typescript,
30+
clean: true,
31+
abortOnError: false,
32+
transformers: [importPathTransformer]
33+
}),
34+
json()
35+
];
36+
37+
const es5Builds = es5BuildsNoPlugin.map(build => ({
38+
...build,
39+
plugins: es5BuildPlugins,
40+
treeshake: {
41+
moduleSideEffects: false
42+
}
43+
}));
44+
45+
/**
46+
* ES2017 Builds
47+
*/
48+
const es2017BuildPlugins = [
49+
typescriptPlugin({
50+
typescript,
51+
tsconfigOverride: {
52+
compilerOptions: {
53+
target: 'es2017'
54+
}
55+
},
56+
abortOnError: false,
57+
clean: true,
58+
transformers: [importPathTransformer]
59+
}),
60+
json({ preferConst: true })
61+
];
62+
63+
const es2017Builds = es2017BuildsNoPlugin.map(build => ({
64+
...build,
65+
plugins: es2017BuildPlugins,
66+
treeshake: {
67+
moduleSideEffects: false
68+
}
69+
}));
70+
71+
export default [...es5Builds, ...es2017Builds];

0 commit comments

Comments
 (0)