Skip to content

Commit e0d9441

Browse files
committed
chore: build single output dist file
1 parent 3b7bc23 commit e0d9441

4 files changed

Lines changed: 104 additions & 13 deletions

File tree

.babelrc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
{
22
"presets": [
3-
"@babel/preset-env"
4-
]
3+
[
4+
"@babel/preset-env", {
5+
"modules": "cjs"
6+
}
7+
]
8+
],
9+
10+
"plugins": [
11+
"add-module-exports"
12+
],
13+
14+
"env": {
15+
"rollup": {
16+
"presets": [
17+
[
18+
"@babel/preset-env", {
19+
"modules": "false"
20+
}
21+
]
22+
]
23+
}
24+
}
525
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,24 @@
4545
"@babel/preset-env": "7.9.0",
4646
"@babel/register": "7.9.0",
4747
"@types/prettier": "1.19.1",
48+
"babel-plugin-add-module-exports": "1.0.2",
4849
"eslint": "6.8.0",
4950
"eslint-config-google": "0.14.0",
5051
"fancy-log": "1.3.3",
5152
"gulp": "4.0.2",
52-
"gulp-babel": "8.0.0",
5353
"gulp-bump": "3.1.3",
5454
"gulp-conventional-changelog": "2.0.29",
5555
"gulp-eslint": "6.0.0",
5656
"gulp-git": "2.10.1",
5757
"gulp-jasmine": "4.0.0",
58-
"gulp-prettier": "2.3.0",
5958
"jasmine-core": "3.5.0",
6059
"lodash.startswith": "4.2.1",
6160
"q": "1.5.1",
6261
"rimraf": "3.0.2",
6362
"rollup": "1.32.0",
63+
"rollup-plugin-babel": "4.4.0",
64+
"rollup-plugin-license": "1.0.0",
65+
"rollup-plugin-strip-banner": "1.2.0",
6466
"tmp": "0.1.0"
6567
}
6668
}

scripts/build/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@
2222
* SOFTWARE.
2323
*/
2424

25-
const path = require('path');
26-
const gulp = require('gulp');
27-
const babel = require('gulp-babel');
28-
const prettier = require('gulp-prettier');
29-
const config = require('../config');
25+
const rollup = require('rollup');
26+
const config = require('./rollup.config');
3027

3128
module.exports = function build() {
32-
return gulp.src(path.join(config.src, '*.js'))
33-
.pipe(babel())
34-
.pipe(prettier())
35-
.pipe(gulp.dest(config.dist));
29+
return rollup.rollup(config).then((bundle) => (
30+
Promise.all(config.output.map((output) => (
31+
bundle.write(output)
32+
)))
33+
));
3634
};

scripts/build/rollup.config.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2017-2020 Mickael Jeanroy
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
const path = require('path');
26+
const prettier = require('prettier');
27+
const stripBanner = require('rollup-plugin-strip-banner');
28+
const babel = require('rollup-plugin-babel');
29+
const license = require('rollup-plugin-license');
30+
const config = require('../config');
31+
const pkg = require('../../package.json');
32+
33+
module.exports = {
34+
input: path.join(config.src, 'index.js'),
35+
36+
output: [
37+
{
38+
format: 'cjs',
39+
file: path.join(config.dist, 'index.js'),
40+
},
41+
],
42+
43+
plugins: [
44+
stripBanner(),
45+
46+
babel({
47+
envName: 'rollup',
48+
}),
49+
50+
license({
51+
banner: {
52+
content: {
53+
file: path.join(config.root, 'LICENSE'),
54+
},
55+
},
56+
}),
57+
58+
{
59+
renderChunk(code) {
60+
return prettier.format(code, {
61+
parser: 'babel',
62+
});
63+
},
64+
},
65+
],
66+
67+
external: [
68+
...Object.keys(pkg.dependencies),
69+
...Object.keys(pkg.peerDependencies),
70+
],
71+
};

0 commit comments

Comments
 (0)