Skip to content

Commit 5380a81

Browse files
committed
use shared config for app exp
1 parent fdf1104 commit 5380a81

File tree

4 files changed

+146
-82
lines changed

4 files changed

+146
-82
lines changed

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

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import typescriptPlugin from 'rollup-plugin-typescript2';
1919
import typescript from 'typescript';
2020
import json from 'rollup-plugin-json';
2121
import pkg from './package.json';
22+
import { es2017BuildsNoPlugin, es5BuildsNoPlugin } from './rollup.shared';
2223

2324
const deps = Object.keys(
2425
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
@@ -34,26 +35,10 @@ const es5BuildPlugins = [
3435
json()
3536
];
3637

37-
const es5Builds = [
38-
/**
39-
* Browser Builds
40-
*/
41-
{
42-
input: 'src/index.ts',
43-
output: [{ file: pkg.browser, 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.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-
];
38+
const es5Builds = es5BuildsNoPlugin.map(build => ({
39+
...build,
40+
plugins: es5BuildPlugins
41+
}));
5742

5843
/**
5944
* ES2017 Builds
@@ -72,20 +57,9 @@ const es2017BuildPlugins = [
7257
})
7358
];
7459

75-
const es2017Builds = [
76-
/**
77-
* Browser Builds
78-
*/
79-
{
80-
input: 'src/index.ts',
81-
output: {
82-
file: pkg.esm2017,
83-
format: 'es',
84-
sourcemap: true
85-
},
86-
plugins: es2017BuildPlugins,
87-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
88-
}
89-
];
60+
const es2017Builds = es2017BuildsNoPlugin.map(build => ({
61+
...build,
62+
plugins: es2017BuildPlugins
63+
}));
9064

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

packages-exp/app-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
@@ -37,32 +33,13 @@ const es5BuildPlugins = [
3733
json()
3834
];
3935

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

6744
/**
6845
* ES2017 Builds
@@ -83,23 +60,12 @@ const es2017BuildPlugins = [
8360
})
8461
];
8562

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

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

packages-exp/app-exp/rollup.shared.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
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.browser, 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.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+
export const es2017BuildsNoPlugin = [
43+
/**
44+
* Browser Builds
45+
*/
46+
{
47+
input: 'src/index.ts',
48+
output: {
49+
file: pkg.esm2017,
50+
format: 'es',
51+
sourcemap: true
52+
},
53+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
54+
}
55+
];
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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 pkg from './package.json';
22+
23+
const deps = Object.keys(
24+
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
25+
);
26+
27+
/**
28+
* ES5 Builds
29+
*/
30+
const es5BuildPlugins = [typescriptPlugin({ typescript }), json()];
31+
32+
const es5Builds = [
33+
{
34+
input: 'src/index.ts',
35+
output: [
36+
{ file: pkg.main, format: 'cjs', sourcemap: true },
37+
{ file: pkg.module, format: 'es', sourcemap: true }
38+
],
39+
plugins: es5BuildPlugins,
40+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
41+
}
42+
];
43+
44+
/**
45+
* ES2017 Builds
46+
*/
47+
48+
const es2017BuildPlugins = [
49+
typescriptPlugin({
50+
typescript,
51+
tsconfigOverride: {
52+
compilerOptions: {
53+
target: 'es2017'
54+
}
55+
}
56+
}),
57+
json({ preferConst: true })
58+
];
59+
60+
const es2017Builds = [
61+
{
62+
input: 'src/index.ts',
63+
output: [{ file: pkg.esm2017, format: 'es', sourcemap: true }],
64+
plugins: es2017BuildPlugins,
65+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
66+
}
67+
];
68+
69+
export default [...es5Builds, ...es2017Builds];

0 commit comments

Comments
 (0)